Class: Yao::Resources::Resource

Inherits:
Base
  • Object
show all
Includes:
ProjectAssociationable
Defined in:
lib/yao/resources/resource.rb

Instance Attribute Summary

Attributes included from RestfullyAccessible

#service

Instance Method Summary collapse

Methods included from ProjectAssociationable

included, #project

Methods inherited from Base

#[], #[]=, add_instantiation_name_list, #destroy, friendly_attributes, #initialize, instantiation?, map_attribute_to_attribute, map_attribute_to_resource, map_attribute_to_resources, map_attributes_to_time, #to_hash, #update

Methods included from RestfullyAccessible

#admin=, #api_version, #api_version=, #as_member, #client, #create, #destroy, extended, #find_by_name, #get, #get!, #list, #resources_path, #resources_path=, #return_single_on_querying, #return_single_on_querying=, #update

Constructor Details

This class inherits a constructor from Yao::Resources::Base

Instance Method Details

#first_sampled_atDate

Returns:

  • (Date)


27
28
29
# File 'lib/yao/resources/resource.rb', line 27

def first_sampled_at
  Time.parse first_sample_timestamp
end

#get_meter(name) ⇒ Array<Yao::Sample>

Returns:

  • (Array<Yao::Sample>)


32
33
34
35
36
# File 'lib/yao/resources/resource.rb', line 32

def get_meter(name)
  if link = links.find{|l| l["rel"] == name }
    Yao::Sample.list(link["href"])
  end
end

#idString

Returns:

  • (String)


12
13
14
# File 'lib/yao/resources/resource.rb', line 12

def id
  resource_id
end

#last_sampled_atDate

Returns:

  • (Date)


22
23
24
# File 'lib/yao/resources/resource.rb', line 22

def last_sampled_at
  Time.parse last_sample_timestamp
end

#metersHash

Returns:

  • (Hash)


39
40
41
# File 'lib/yao/resources/resource.rb', line 39

def meters
  links.map{|l| l["rel"] }.delete_if{|n| n == 'self' }
end

#userYao::User

Returns:

  • (Yao::User)


17
18
19
# File 'lib/yao/resources/resource.rb', line 17

def user
  @user ||= Yao::User.get(user_id)
end