Class: Hermeneutics::Message::Headers::Entry
- Inherits:
-
Object
- Object
- Hermeneutics::Message::Headers::Entry
- Defined in:
- lib/hermeneutics/message.rb
Constant Summary collapse
- LINE_LENGTH =
78
- INDENT =
" "
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#sep ⇒ Object
readonly
Returns the value of attribute sep.
Class Method Summary collapse
Instance Method Summary collapse
- #contents(type) ⇒ Object
-
#initialize(name, sep, data) ⇒ Entry
constructor
A new instance of Entry.
- #name_is?(name) ⇒ Boolean
- #reset(type) ⇒ Object
- #set(*contents) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, sep, data) ⇒ Entry
Returns a new instance of Entry.
240 241 242 |
# File 'lib/hermeneutics/message.rb', line 240 def initialize name, sep, data @name, @sep, @data, @contents = name, sep, data end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
239 240 241 |
# File 'lib/hermeneutics/message.rb', line 239 def data @data end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
239 240 241 |
# File 'lib/hermeneutics/message.rb', line 239 def name @name end |
#sep ⇒ Object (readonly)
Returns the value of attribute sep.
239 240 241 |
# File 'lib/hermeneutics/message.rb', line 239 def sep @sep end |
Class Method Details
.build_name(name) ⇒ Object
230 231 232 233 234 235 236 237 |
# File 'lib/hermeneutics/message.rb', line 230 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
225 226 227 228 229 |
# File 'lib/hermeneutics/message.rb', line 225 def create name, *contents name = build_name name i = new name.to_s, ": ", nil i.set *contents end |
.parse(str) ⇒ Object
219 220 221 222 223 224 |
# File 'lib/hermeneutics/message.rb', line 219 def parse str str =~ /:\s*/ or raise ParseError, "Header line without a colon: #{str}" data = $' new $`, $&, data end |
Instance Method Details
#contents(type) ⇒ Object
246 247 248 249 250 251 252 253 254 255 |
# File 'lib/hermeneutics/message.rb', line 246 def contents type if type then unless @contents and @contents.is_a? type then @contents = type.parse @data end @contents else @data end end |
#name_is?(name) ⇒ Boolean
256 257 258 |
# File 'lib/hermeneutics/message.rb', line 256 def name_is? name (@name.casecmp name).zero? end |
#reset(type) ⇒ Object
279 280 281 282 283 284 285 |
# File 'lib/hermeneutics/message.rb', line 279 def reset type if type then c = contents type @data = mk_lines c.encode if c end self end |
#set(*contents) ⇒ Object
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/hermeneutics/message.rb', line 259 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
243 244 245 |
# File 'lib/hermeneutics/message.rb', line 243 def to_s "#@name#@sep#@data" end |