Class: ODDB::Util::Code
- Inherits:
-
Object
- Object
- ODDB::Util::Code
- Includes:
- OddbUri
- Defined in:
- lib/oddb/util/code.rb,
lib/oddb/export/yaml.rb,
lib/oddb/persistence/odba/util/code.rb
Constant Summary
Constants included from OddbUri
Instance Attribute Summary collapse
-
#country ⇒ Object
Returns the value of attribute country.
-
#format ⇒ Object
Returns the value of attribute format.
-
#type ⇒ Object
Returns the value of attribute type.
-
#value(date = Date.today) ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(type, value, country, valid_from = Date.today) ⇒ Code
constructor
A new instance of Code.
- #is_for?(type, country) ⇒ Boolean
- #to_s ⇒ Object
- #to_yaml_map(map) ⇒ Object
- #to_yaml_properties ⇒ Object
Methods included from OddbUri
Constructor Details
#initialize(type, value, country, valid_from = Date.today) ⇒ Code
Returns a new instance of Code.
10 11 12 13 |
# File 'lib/oddb/util/code.rb', line 10 def initialize(type, value, country, valid_from=Date.today) @values = { valid_from => value} @type, @country = type.to_s.downcase, country.to_s.upcase end |
Instance Attribute Details
#country ⇒ Object
Returns the value of attribute country.
9 10 11 |
# File 'lib/oddb/util/code.rb', line 9 def country @country end |
#format ⇒ Object
Returns the value of attribute format.
9 10 11 |
# File 'lib/oddb/util/code.rb', line 9 def format @format end |
#type ⇒ Object
Returns the value of attribute type.
9 10 11 |
# File 'lib/oddb/util/code.rb', line 9 def type @type end |
#value(date = Date.today) ⇒ Object
Returns the value of attribute value.
9 10 11 |
# File 'lib/oddb/util/code.rb', line 9 def value @value end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/oddb/util/code.rb', line 54 def ==(other) if(other.is_a?(Code)) other.type == @type && other.value == value \ && other.country == @country elsif(other.is_a?(Hash)) res = other[:type].to_s.downcase == @type \ && other[:value] == value \ && other[:country] == @country else value == other || value.to_s == other end end |
#hash ⇒ Object
14 15 16 |
# File 'lib/oddb/util/code.rb', line 14 def hash [@type, @value, @country].hash end |
#is_for?(type, country) ⇒ Boolean
17 18 19 |
# File 'lib/oddb/util/code.rb', line 17 def is_for?(type, country) @type == type.to_s.downcase && @country == country.to_s.upcase end |
#to_s ⇒ Object
33 34 35 |
# File 'lib/oddb/util/code.rb', line 33 def to_s format % value end |
#to_yaml_map(map) ⇒ Object
56 57 58 59 |
# File 'lib/oddb/export/yaml.rb', line 56 def to_yaml_map(map) super map.add('value', value) end |
#to_yaml_properties ⇒ Object
60 61 62 |
# File 'lib/oddb/export/yaml.rb', line 60 def to_yaml_properties super - [:@values] end |