Class: VersionOne::AssetRef
- Inherits:
-
Object
- Object
- VersionOne::AssetRef
- Defined in:
- lib/version-one/asset_ref.rb
Instance Attribute Summary collapse
-
#href ⇒ Object
readonly
Returns the value of attribute href.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Class Method Summary collapse
Instance Method Summary collapse
- #get(*fields) ⇒ Object
-
#initialize(xml_or_asset) ⇒ AssetRef
constructor
A new instance of AssetRef.
- #inspect ⇒ Object
- #method_missing(method, *args, &block) ⇒ Object
- #to_xml ⇒ Object
Constructor Details
#initialize(xml_or_asset) ⇒ AssetRef
Returns a new instance of AssetRef.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/version-one/asset_ref.rb', line 7 def initialize(xml_or_asset) case xml_or_asset when Asset @asset = xml_or_asset @id = @asset.id @href = @asset.href else @href = xml_or_asset.attributes['href'] @id = xml_or_asset.attributes['idref'] end raise ArgumentError, "Could not get id and href" unless @id && @href end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
39 40 41 |
# File 'lib/version-one/asset_ref.rb', line 39 def method_missing(method, *args, &block) get.send(method, *args, &block) end |
Instance Attribute Details
#href ⇒ Object (readonly)
Returns the value of attribute href.
5 6 7 |
# File 'lib/version-one/asset_ref.rb', line 5 def href @href end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/version-one/asset_ref.rb', line 5 def id @id end |
Class Method Details
Instance Method Details
#get(*fields) ⇒ Object
24 25 26 |
# File 'lib/version-one/asset_ref.rb', line 24 def get(*fields) @asset ||= get_asset(*fields) end |
#inspect ⇒ Object
28 29 30 |
# File 'lib/version-one/asset_ref.rb', line 28 def inspect "#<AssetRef:#{@href}>" end |
#to_xml ⇒ Object
32 33 34 35 36 37 |
# File 'lib/version-one/asset_ref.rb', line 32 def to_xml xml = XML::Node.new('Asset') xml.attributes['href'] = @href xml.attributes['idref'] = @id xml end |