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.
140 141 142 |
# File 'lib/hermeneutics/message.rb', line 140 def initialize name, data @name, @data, @contents = name, data end |
Class Attribute Details
.indent ⇒ Object
Returns the value of attribute indent.
111 112 113 |
# File 'lib/hermeneutics/message.rb', line 111 def indent @indent end |
.line_max ⇒ Object
Returns the value of attribute line_max.
111 112 113 |
# File 'lib/hermeneutics/message.rb', line 111 def line_max @line_max end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
138 139 140 |
# File 'lib/hermeneutics/message.rb', line 138 def data @data end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
138 139 140 |
# File 'lib/hermeneutics/message.rb', line 138 def name @name end |
Class Method Details
.build_name(name) ⇒ Object
127 128 129 130 131 132 133 134 |
# File 'lib/hermeneutics/message.rb', line 127 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
121 122 123 124 125 |
# File 'lib/hermeneutics/message.rb', line 121 def create name, *contents name = build_name name i = new name.to_s, nil i.set *contents end |
.parse(str) ⇒ Object
115 116 117 118 119 |
# File 'lib/hermeneutics/message.rb', line 115 def parse str str =~ /:\s*/ or raise ParseError, "Header line without a colon: #{str}" new $`, $' end |
Instance Method Details
#contents(type = nil) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/hermeneutics/message.rb', line 148 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
167 168 169 |
# File 'lib/hermeneutics/message.rb', line 167 def name_is? name (@name.casecmp name).zero? end |
#reset(type) ⇒ Object
192 193 194 195 196 197 198 199 200 |
# File 'lib/hermeneutics/message.rb', line 192 def reset type d = if type then (contents type).encode else @contents end @data = mk_lines d self end |
#set(*contents) ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/hermeneutics/message.rb', line 171 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
144 145 146 |
# File 'lib/hermeneutics/message.rb', line 144 def to_s "#@name: #@data" end |