Class: ActsAsHavingStringId::StringId
- Inherits:
-
Object
- Object
- ActsAsHavingStringId::StringId
- Defined in:
- lib/acts_as_having_string_id/string_id.rb
Defined Under Namespace
Classes: Type
Instance Attribute Summary collapse
-
#int_value ⇒ Object
readonly
Returns the value of attribute int_value.
-
#string_value ⇒ Object
readonly
Returns the value of attribute string_value.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #id ⇒ Object
-
#initialize(klass, value) ⇒ StringId
constructor
A new instance of StringId.
- #inspect ⇒ Object
- #quoted_id ⇒ Object
- #to_i ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(klass, value) ⇒ StringId
Returns a new instance of StringId.
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/acts_as_having_string_id/string_id.rb', line 5 def initialize(klass, value) if value == nil @string_value = nil @int_value = nil elsif value.is_a? String @string_value = value @int_value = klass.id_int(value) else @int_value = value @string_value = klass.id_string(value) end end |
Instance Attribute Details
#int_value ⇒ Object (readonly)
Returns the value of attribute int_value.
3 4 5 |
# File 'lib/acts_as_having_string_id/string_id.rb', line 3 def int_value @int_value end |
#string_value ⇒ Object (readonly)
Returns the value of attribute string_value.
3 4 5 |
# File 'lib/acts_as_having_string_id/string_id.rb', line 3 def string_value @string_value end |
Instance Method Details
#==(other) ⇒ Object
38 39 40 |
# File 'lib/acts_as_having_string_id/string_id.rb', line 38 def ==(other) other.is_a?(StringId) && other.int_value == int_value end |
#id ⇒ Object
22 23 24 |
# File 'lib/acts_as_having_string_id/string_id.rb', line 22 def id int_value end |
#inspect ⇒ Object
18 19 20 |
# File 'lib/acts_as_having_string_id/string_id.rb', line 18 def inspect "#{int_value}/#{string_value}" end |
#quoted_id ⇒ Object
26 27 28 |
# File 'lib/acts_as_having_string_id/string_id.rb', line 26 def quoted_id int_value end |
#to_i ⇒ Object
34 35 36 |
# File 'lib/acts_as_having_string_id/string_id.rb', line 34 def to_i int_value end |
#to_s ⇒ Object
30 31 32 |
# File 'lib/acts_as_having_string_id/string_id.rb', line 30 def to_s string_value end |