Class: HyperTrack::SharedResource

Direct Known Subclasses

Action, User

Constant Summary collapse

VALID_VEHICLE_TYPES =
:flight, :train, :ship
[:walking, :bicycle, :motorcycle, :car, :'3-wheeler', :van]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ApiOperations::Common::Create

create

Methods included from ApiOperations::Common::Retrieve

retrieve

Methods included from ApiOperations::Common::List

list

Methods included from ApiOperations::Common::Nearby

nearby

Methods included from ApiOperations::Common::RetrieveByUniqueId

retrieve_by_unique_id

Methods included from ApiOperations::Common::Update

#update

Methods included from ApiOperations::Common::Get

#get, #get_list

Methods included from ApiOperations::Common::Patch

#patch

Constructor Details

#initialize(id, opts) ⇒ SharedResource

Returns a new instance of SharedResource.



16
17
18
19
# File 'lib/hypertrack/shared_resource.rb', line 16

def initialize(id, opts)
  @id = id
  @values = Util.symbolize_keys(opts)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object (protected)



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/hypertrack/shared_resource.rb', line 43

def method_missing(name, *args)
  if name[-1] == "="
    name = name[0..-2]

    if @values.has_key?(name.to_sym)
      self[name.to_sym] = args[0]
      return
    end

  elsif @values.has_key?(name.to_sym)
    return @values[name.to_sym]
  end

  super
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



14
15
16
# File 'lib/hypertrack/shared_resource.rb', line 14

def id
  @id
end

Class Method Details

.get_class_nameObject



61
62
63
64
# File 'lib/hypertrack/shared_resource.rb', line 61

def self.get_class_name
  # To-Do: Umm.. Find some better approach
  Object.const_get(self.name)
end

Instance Method Details

#[](k) ⇒ Object



21
22
23
# File 'lib/hypertrack/shared_resource.rb', line 21

def [](k)
  @values[k.to_sym]
end

#[]=(k, v) ⇒ Object



25
26
27
# File 'lib/hypertrack/shared_resource.rb', line 25

def []=(k, v)
  @values[k.to_sym] = v
end

#keysObject



29
30
31
# File 'lib/hypertrack/shared_resource.rb', line 29

def keys
  @values.keys
end

#to_jsonObject



37
38
39
# File 'lib/hypertrack/shared_resource.rb', line 37

def to_json
  JSON.generate(@values)
end

#valuesObject



33
34
35
# File 'lib/hypertrack/shared_resource.rb', line 33

def values
  @values.values
end