Class: Presser::LocalFile
- Inherits:
-
Object
- Object
- Presser::LocalFile
- Defined in:
- lib/local_file.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#params ⇒ Object
Returns the value of attribute params.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
-
#initialize(filename) ⇒ LocalFile
constructor
A new instance of LocalFile.
- #parse_all_lines ⇒ Object
- #parse_line(line) ⇒ Object
Constructor Details
#initialize(filename) ⇒ LocalFile
Returns a new instance of LocalFile.
5 6 7 8 9 10 11 12 |
# File 'lib/local_file.rb', line 5 def initialize filename @in_header = true @body = "" @filename = filename @params = {} parse_all_lines # puts "The title: #{@title}" end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
4 5 6 |
# File 'lib/local_file.rb', line 4 def body @body end |
#params ⇒ Object
Returns the value of attribute params.
4 5 6 |
# File 'lib/local_file.rb', line 4 def params @params end |
#title ⇒ Object
Returns the value of attribute title.
4 5 6 |
# File 'lib/local_file.rb', line 4 def title @title end |
Instance Method Details
#parse_all_lines ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/local_file.rb', line 14 def parse_all_lines File.readlines(@filename).each do |line| line = line.strip if @in_header parse_line line else # puts "Body: '#{line}'" body << line << "\n" end end # puts "params: #{@params}" @title = params["title"] || "Default title" end |
#parse_line(line) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/local_file.rb', line 28 def parse_line line if line == "# End of header" @in_header = false else if line =~ /(.*):(.*)/ # puts "match: #{line}" key = $1.strip val = $2.strip @params[key] = val else # puts "No match: #{line}" end end end |