Class: HaystackRuby::Object

Inherits:
Object
  • Object
show all
Defined in:
lib/haystack_ruby/object.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(val) ⇒ Object

initialize with a encoded json string



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/haystack_ruby/object.rb', line 20

def initialize val
  case val
    when Array
      @haystack_type = "Array" #may want to decode array components?
      @value = val
    when TrueClass
      @haystack_type = "Boolean"
      @value = val
    when FalseClass
      @haystack_type = "Boolean"
      @value = val
    when NilClass
      @haystack_type = 'Null'
      @value = val
    when String
      # Map to Haystack type per http://project-haystack.org/doc/Json
      case val
        when /\Am:.*/
          extend HaystackRuby::Types::Marker
        when /\Az:.*/
          extend HaystackRuby::Types::NA
        when /\An:.*/
          extend HaystackRuby::Types::Number
        when /\Ar:.*/
          extend HaystackRuby::Types::Ref
        when /\As:.*/
          extend HaystackRuby::Types::Str
        when /\Ad:.*/
          extend HaystackRuby::Types::Date
        when /\Ah:.*/
          extend HaystackRuby::Types::Time
        when /\At:.*/
          extend HaystackRuby::Types::DateTime
        when /\Au:.*/
          extend HaystackRuby::Types::Uri
        when /\Ab:.*/
          extend HaystackRuby::Types::Bin
        when /\Ac:.*/
          extend HaystackRuby::Types::Coord
        when /\Ax:.*/
          raise HaystackRuby::Error, "parsing of XStr type is not supported for string val #{val}"
        else
          raise HaystackRuby::Error, "unrecognized type for string val #{val}"
      end
    else
      raise HaystackRuby::Error, "unrecognized type for val #{val}"
    end
  set_fields val
end

Instance Attribute Details

#descriptionObject (readonly)

May be present, depending on type



18
19
20
# File 'lib/haystack_ruby/object.rb', line 18

def description
  @description
end

#haystack_typeObject (readonly)

Always present



16
17
18
# File 'lib/haystack_ruby/object.rb', line 16

def haystack_type
  @haystack_type
end

#unitObject (readonly)

May be present, depending on type



18
19
20
# File 'lib/haystack_ruby/object.rb', line 18

def unit
  @unit
end

#valueObject (readonly)

Always present



16
17
18
# File 'lib/haystack_ruby/object.rb', line 16

def value
  @value
end