Class: Amountable::VirtualAmount

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model, Operations
Defined in:
lib/amountable/virtual_amount.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Operations

#*, #+, #-, #/, #to_money

Instance Attribute Details

#amountableObject

Returns the value of attribute amountable.



7
8
9
# File 'lib/amountable/virtual_amount.rb', line 7

def amountable
  @amountable
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/amountable/virtual_amount.rb', line 7

def name
  @name
end

#persistableObject

Returns the value of attribute persistable.



7
8
9
# File 'lib/amountable/virtual_amount.rb', line 7

def persistable
  @persistable
end

#value_centsObject

Returns the value of attribute value_cents.



7
8
9
# File 'lib/amountable/virtual_amount.rb', line 7

def value_cents
  @value_cents
end

#value_currencyObject

Returns the value of attribute value_currency.



7
8
9
# File 'lib/amountable/virtual_amount.rb', line 7

def value_currency
  @value_currency
end

Instance Method Details

#new_record?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/amountable/virtual_amount.rb', line 22

def new_record?
  true
end

#persisted?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/amountable/virtual_amount.rb', line 26

def persisted?
  false
end

#saveObject

Raises:

  • (StandardError)


30
31
32
33
# File 'lib/amountable/virtual_amount.rb', line 30

def save
  raise StandardError.new("Can't persist amount to database") if persistable == false
  super
end

#valueObject



13
14
15
# File 'lib/amountable/virtual_amount.rb', line 13

def value
  Money.new(value_cents, value_currency)
end

#value=(val) ⇒ Object



17
18
19
20
# File 'lib/amountable/virtual_amount.rb', line 17

def value=(val)
  self.value_cents = value.fractional
  self.value_currency = value.currency.iso_code
end