Class: ODDB::Util::Code

Inherits:
Object
  • Object
show all
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

OddbUri::YAML_URI

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from OddbUri

#to_yaml, #to_yaml_type

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

#countryObject

Returns the value of attribute country.



9
10
11
# File 'lib/oddb/util/code.rb', line 9

def country
  @country
end

#formatObject

Returns the value of attribute format.



9
10
11
# File 'lib/oddb/util/code.rb', line 9

def format
  @format
end

#typeObject

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

#hashObject



14
15
16
# File 'lib/oddb/util/code.rb', line 14

def hash
  [@type, @value, @country].hash
end

#is_for?(type, country) ⇒ Boolean

Returns:

  • (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_sObject



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_propertiesObject



60
61
62
# File 'lib/oddb/export/yaml.rb', line 60

def to_yaml_properties
  super - [:@values]
end