Class: Archive::Pecan::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/archive/pecan/attribute.rb

Overview

Abstract representation of a component attribute as a key-value pair.

Author:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, value = nil) ⇒ Attribute

Initializes a component attribute.

Parameters:

  • name (String) (defaults to: nil)

    Descriptive name of the attribute.

  • value (String) (defaults to: nil)

    Value of the specified 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

#nameString

Returns Descriptive name of the attribute.

Returns:

  • (String)

    Descriptive name of the attribute.



11
12
13
# File 'lib/archive/pecan/attribute.rb', line 11

def name
  @name
end

#valueString

Returns Value of the attribute.

Returns:

  • (String)

    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.

Parameters:

  • line (String)

    Attribute file line.

Returns:

  • (Attribute)

    Parsed attribute object from 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_sString

String representation of this object just as it is represented in an attribute file.

Returns:

  • (String)

    Object as 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_strObject

See Also:



54
55
56
# File 'lib/archive/pecan/attribute.rb', line 54

def to_str
  to_s
end