Class: ActsAsHavingStringId::StringId

Inherits:
Object
  • Object
show all
Defined in:
lib/acts_as_having_string_id/string_id.rb

Defined Under Namespace

Classes: Type

Instance Attribute Summary collapse

Instance Method Summary collapse

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_valueObject (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_valueObject (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

#idObject



22
23
24
# File 'lib/acts_as_having_string_id/string_id.rb', line 22

def id
  int_value
end

#inspectObject



18
19
20
# File 'lib/acts_as_having_string_id/string_id.rb', line 18

def inspect
  "#{int_value}/#{string_value}"
end

#quoted_idObject



26
27
28
# File 'lib/acts_as_having_string_id/string_id.rb', line 26

def quoted_id
  int_value
end

#to_iObject



34
35
36
# File 'lib/acts_as_having_string_id/string_id.rb', line 34

def to_i
  int_value
end

#to_sObject



30
31
32
# File 'lib/acts_as_having_string_id/string_id.rb', line 30

def to_s
  string_value
end