Class: Tinypass::PriceOption
- Inherits:
-
Object
- Object
- Tinypass::PriceOption
- Defined in:
- lib/tinypass/price_option.rb
Instance Attribute Summary collapse
-
#access_period ⇒ Object
Returns the value of attribute access_period.
-
#caption ⇒ Object
Returns the value of attribute caption.
-
#end_date_in_secs ⇒ Object
Returns the value of attribute end_date_in_secs.
-
#price ⇒ Object
Returns the value of attribute price.
-
#split_pays ⇒ Object
readonly
Returns the value of attribute split_pays.
-
#start_date_in_secs ⇒ Object
Returns the value of attribute start_date_in_secs.
Instance Method Summary collapse
- #access_period_in_msecs ⇒ Object
- #access_period_in_secs ⇒ Object
- #active?(timestamp = nil) ⇒ Boolean
- #add_split_pay(email, amount) ⇒ Object
-
#initialize(price, access_period = nil, start_date_in_secs = nil, end_date_in_secs = nil) ⇒ PriceOption
constructor
A new instance of PriceOption.
- #to_s ⇒ Object
Constructor Details
#initialize(price, access_period = nil, start_date_in_secs = nil, end_date_in_secs = nil) ⇒ PriceOption
Returns a new instance of PriceOption.
6 7 8 9 10 11 12 13 |
# File 'lib/tinypass/price_option.rb', line 6 def initialize(price, access_period = nil, start_date_in_secs = nil, end_date_in_secs = nil) @split_pays = {} @price, @access_period = price, access_period @start_date_in_secs = TokenData.convert_to_epoch_seconds(start_date_in_secs) if start_date_in_secs @end_date_in_secs = TokenData.convert_to_epoch_seconds(end_date_in_secs) if end_date_in_secs end |
Instance Attribute Details
#access_period ⇒ Object
Returns the value of attribute access_period.
3 4 5 |
# File 'lib/tinypass/price_option.rb', line 3 def access_period @access_period end |
#caption ⇒ Object
Returns the value of attribute caption.
3 4 5 |
# File 'lib/tinypass/price_option.rb', line 3 def caption @caption end |
#end_date_in_secs ⇒ Object
Returns the value of attribute end_date_in_secs.
3 4 5 |
# File 'lib/tinypass/price_option.rb', line 3 def end_date_in_secs @end_date_in_secs end |
#price ⇒ Object
Returns the value of attribute price.
3 4 5 |
# File 'lib/tinypass/price_option.rb', line 3 def price @price end |
#split_pays ⇒ Object (readonly)
Returns the value of attribute split_pays.
4 5 6 |
# File 'lib/tinypass/price_option.rb', line 4 def split_pays @split_pays end |
#start_date_in_secs ⇒ Object
Returns the value of attribute start_date_in_secs.
3 4 5 |
# File 'lib/tinypass/price_option.rb', line 3 def start_date_in_secs @start_date_in_secs end |
Instance Method Details
#access_period_in_msecs ⇒ Object
15 16 17 |
# File 'lib/tinypass/price_option.rb', line 15 def access_period_in_msecs Utils.parse_loose_period_in_msecs(@access_period) end |
#access_period_in_secs ⇒ Object
19 20 21 |
# File 'lib/tinypass/price_option.rb', line 19 def access_period_in_secs access_period_in_msecs / 1000 end |
#active?(timestamp = nil) ⇒ Boolean
23 24 25 26 27 28 29 30 |
# File 'lib/tinypass/price_option.rb', line 23 def active?( = nil) ||= Time.now.to_i = TokenData.convert_to_epoch_seconds() return false if start_date_in_secs && < start_date_in_secs return false if end_date_in_secs && > end_date_in_secs return true end |
#add_split_pay(email, amount) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/tinypass/price_option.rb', line 37 def add_split_pay(email, amount) amount = amount[0..-2].to_f / 100.0 if amount.end_with?('%') amount = amount.to_f @split_pays[email] = amount end |
#to_s ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/tinypass/price_option.rb', line 44 def to_s string = "Price:#{ price }\tPeriod:#{ access_period }\tTrial Period:#{ access_period }" if start_date_in_secs string << "\tStart:#{ start_date_in_secs }:#{ Time.at(start_date_in_secs).strftime('%a, %d %b %Y %H %M %S') }" end if end_date_in_secs string << "\tEnd:#{ end_date_in_secs }:#{ Time.at(end_date_in_secs).strftime('%a, %d %b %Y %H %M %S') }" end string << "\tCaption:#{ caption }" if caption if @split_pays.any? @split_pays.each do |email, amount| string << "\tSplit:#{ email }:#{ amount }" end end string end |