Module: ODDB::Util::M10lMethods

Includes:
Comparable
Included in:
M10lDocument, Multilingual
Defined in:
lib/oddb/util/multilingual.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/oddb/util/multilingual.rb', line 19

def method_missing(meth, *args, &block)
  case meth.to_s
  when /^[a-z]{2}$/
    @canonical[meth]
  when /^([a-z]{2})=$/
    @canonical.store($~[1].to_sym, args.first)
  else
    super(meth, *args, &block)
  end
end

Instance Attribute Details

#canonicalObject (readonly)

Returns the value of attribute canonical.



8
9
10
# File 'lib/oddb/util/multilingual.rb', line 8

def canonical
  @canonical
end

#synonymsObject (readonly)

Returns the value of attribute synonyms.



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

def synonyms
  @synonyms
end

Instance Method Details

#<=>(other) ⇒ Object



45
46
47
# File 'lib/oddb/util/multilingual.rb', line 45

def <=>(other)
  all.sort <=> other.all.sort
end

#==(other) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/oddb/util/multilingual.rb', line 32

def ==(other)
  case other
  when String
    @canonical.values.any? { |val| val == other } \
      || @synonyms.any? { |val| val == other }
  when M10lDocument
    @canonical == other.canonical && @synonyms == other.synonyms
  when M10lMethods
    @canonical == other.canonical
  else
    false
  end
end

#allObject



13
14
15
# File 'lib/oddb/util/multilingual.rb', line 13

def all
  @canonical.values
end

#empty?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/oddb/util/multilingual.rb', line 16

def empty?
  @canonical.empty?
end

#initialize(canonical = {}) ⇒ Object



10
11
12
# File 'lib/oddb/util/multilingual.rb', line 10

def initialize(canonical={})
  @canonical = canonical
end

#to_sObject



29
30
31
# File 'lib/oddb/util/multilingual.rb', line 29

def to_s
  @canonical.values.sort.first.to_s
end