Class: Deb822::Paragraph
- Inherits:
-
Object
- Object
- Deb822::Paragraph
- Extended by:
- Enumerable, Forwardable
- Defined in:
- lib/deb822.rb
Overview
Hash-like structure whose keys are FieldName.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object (also: #store)
- #fetch(key, *default, &block) ⇒ Object
-
#initialize(hash = nil) ⇒ Paragraph
constructor
A new instance of Paragraph.
- #slice(*keys) ⇒ Object
- #update(other) ⇒ Object
Constructor Details
#initialize(hash = nil) ⇒ Paragraph
Returns a new instance of Paragraph.
71 72 73 74 |
# File 'lib/deb822.rb', line 71 def initialize(hash = nil) @hash = {} update(hash) if hash end |
Instance Method Details
#[](key) ⇒ Object
76 77 78 |
# File 'lib/deb822.rb', line 76 def [](key) @hash[Deb822::FieldName(key)] end |
#[]=(key, value) ⇒ Object Also known as: store
80 81 82 |
# File 'lib/deb822.rb', line 80 def []=(key, value) @hash[Deb822::FieldName(key)] = value.to_s end |
#fetch(key, *default, &block) ⇒ Object
85 86 87 |
# File 'lib/deb822.rb', line 85 def fetch(key, *default, &block) @hash.fetch(Deb822::FieldName(key), *default, &block) end |
#slice(*keys) ⇒ Object
95 96 97 |
# File 'lib/deb822.rb', line 95 def slice(*keys) Paragraph.new(@hash.slice(*keys.map(&Deb822.method(:FieldName)))) end |
#update(other) ⇒ Object
89 90 91 92 93 |
# File 'lib/deb822.rb', line 89 def update(other) other.each do |k, v| store(k, v) end end |