Class: Archive::Pecan::Attribute
- Inherits:
-
Object
- Object
- Archive::Pecan::Attribute
- Defined in:
- lib/archive/pecan/attribute.rb
Overview
Abstract representation of a component attribute as a key-value pair.
Instance Attribute Summary collapse
-
#name ⇒ String
Descriptive name of the attribute.
-
#value ⇒ String
Value of the attribute.
Class Method Summary collapse
-
.from_line(line) ⇒ Attribute
Initializes a component attribute from an attribute file line.
Instance Method Summary collapse
-
#initialize(name = nil, value = nil) ⇒ Attribute
constructor
Initializes a component attribute.
-
#to_s ⇒ String
String representation of this object just as it is represented in an attribute file.
- #to_str ⇒ Object
Constructor Details
#initialize(name = nil, value = nil) ⇒ Attribute
Initializes a component attribute.
20 21 22 23 |
# File 'lib/archive/pecan/attribute.rb', line 20 def initialize(name = nil, value = nil) @name = name @value = value end |
Instance Attribute Details
#name ⇒ String
Returns Descriptive name of the attribute.
11 12 13 |
# File 'lib/archive/pecan/attribute.rb', line 11 def name @name end |
#value ⇒ String
Returns Value of the attribute.
14 15 16 |
# File 'lib/archive/pecan/attribute.rb', line 14 def value @value end |
Class Method Details
.from_line(line) ⇒ Attribute
Initializes a component attribute from an attribute file line.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/archive/pecan/attribute.rb', line 30 def self.from_line(line) attr = new # Make sure we have a valid line. line = line.strip return nil if line.empty? # Parse line and populate the object. str = line.split("\t", 2) attr.name = str[0] attr.value = str[1] attr end |
Instance Method Details
#to_s ⇒ String
String representation of this object just as it is represented in an attribute file.
49 50 51 |
# File 'lib/archive/pecan/attribute.rb', line 49 def to_s "#{@name}\t#{value}\n" end |
#to_str ⇒ Object
54 55 56 |
# File 'lib/archive/pecan/attribute.rb', line 54 def to_str to_s end |