Class: Hermeneutics::Message::Header
- Inherits:
-
Object
- Object
- Hermeneutics::Message::Header
- Defined in:
- lib/hermeneutics/message.rb
Class Attribute Summary collapse
-
.indent ⇒ Object
Returns the value of attribute indent.
-
.line_max ⇒ Object
Returns the value of attribute line_max.
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #contents(type = nil) ⇒ Object
-
#initialize(name, data) ⇒ Header
constructor
A new instance of Header.
- #name_is?(name) ⇒ Boolean
- #reset(type) ⇒ Object
- #set(*contents) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, data) ⇒ Header
Returns a new instance of Header.
139 140 141 |
# File 'lib/hermeneutics/message.rb', line 139 def initialize name, data @name, @data, @contents = name, data end |
Class Attribute Details
.indent ⇒ Object
Returns the value of attribute indent.
110 111 112 |
# File 'lib/hermeneutics/message.rb', line 110 def indent @indent end |
.line_max ⇒ Object
Returns the value of attribute line_max.
110 111 112 |
# File 'lib/hermeneutics/message.rb', line 110 def line_max @line_max end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
137 138 139 |
# File 'lib/hermeneutics/message.rb', line 137 def data @data end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
137 138 139 |
# File 'lib/hermeneutics/message.rb', line 137 def name @name end |
Class Method Details
.build_name(name) ⇒ Object
126 127 128 129 130 131 132 133 |
# File 'lib/hermeneutics/message.rb', line 126 def build_name name n = name.to_s unless n.equal? name then n.gsub! /_/, "-" n.gsub! /\b[a-z]/ do |c| c.upcase end end n end |
.create(name, *contents) ⇒ Object
120 121 122 123 124 |
# File 'lib/hermeneutics/message.rb', line 120 def create name, *contents name = build_name name i = new name.to_s, nil i.set *contents end |
.parse(str) ⇒ Object
114 115 116 117 118 |
# File 'lib/hermeneutics/message.rb', line 114 def parse str str =~ /:\s*/ or raise ParseError, "Header line without a colon: #{str}" new $`, $' end |
Instance Method Details
#contents(type = nil) ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/hermeneutics/message.rb', line 147 def contents type = nil if type then if @contents then if not @contents.is_a? type then @contents = type.parse @data end else @contents = type.parse @data end else unless @contents then @contents = @data @contents.strip! @contents.gsub! /\s\+/m, " " end end @contents end |
#name_is?(name) ⇒ Boolean
166 167 168 |
# File 'lib/hermeneutics/message.rb', line 166 def name_is? name (@name.casecmp name).zero? end |
#reset(type) ⇒ Object
191 192 193 194 195 196 197 198 199 |
# File 'lib/hermeneutics/message.rb', line 191 def reset type d = if type then (contents type).encode else @contents end @data = mk_lines d self end |
#set(*contents) ⇒ Object
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/hermeneutics/message.rb', line 170 def set *contents type, *args = *contents d = case type when Class then @contents = type.new *args case (e = @contents.encode) when Array then e when nil then [] else [ e] end when nil then @contents = nil split_args args else @contents = nil split_args contents end @data = mk_lines d self end |
#to_s ⇒ Object
143 144 145 |
# File 'lib/hermeneutics/message.rb', line 143 def to_s "#@name: #@data" end |