Skip to content

Commit aaea40b

Browse files
committed
Add #valid? to PriceChannel
1 parent 02ada51 commit aaea40b

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

lib/ruby_technical_analysis/indicators/price_channel.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ def call
1818
calculate_price_channel
1919
end
2020

21+
# @return [Boolean] Whether the object is valid
22+
def valid?
23+
series.length >= period
24+
end
25+
2126
private
2227

2328
def _highs

spec/ruby_technical_analysis/indicators/price_channel_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ module RubyTechnicalAnalysis
3737
expect(price_channel.call).to eq([2.974, 2.8127])
3838
end
3939
end
40+
41+
describe "#valid?" do
42+
it "returns true if the object is valid" do
43+
expect(price_channel.valid?).to eq(true)
44+
end
45+
46+
it "returns false if the object is invalid" do
47+
expect(described_class.new(series: []).valid?).to eq(false)
48+
end
49+
end
4050
end
4151

4252
describe "secondary series" do

0 commit comments

Comments
 (0)