Class: Sinatra::Soxer::FileReader
- Inherits:
-
Object
- Object
- Sinatra::Soxer::FileReader
- Defined in:
- lib/soxer/main.rb
Overview
The FileReader class
FileReader is responsible for reading a YAML file, that contains the content and metadata for each web page.
FileReader also assumes that each YAML file contains 2 top level fields:
- uuid
-
A Universally Unique Identifier field
- date
-
A standard date and time field
if the fields are not present, they are automatically generated and saved in the file.
Instance Attribute Summary collapse
-
#filename ⇒ Object
Returns the value of attribute filename.
Instance Method Summary collapse
-
#get_content ⇒ Object
The method, that retuns the YAML structure in a ::hashie hash::.
-
#initialize(filename, settings) ⇒ FileReader
constructor
A new instance of FileReader.
Constructor Details
#initialize(filename, settings) ⇒ FileReader
Returns a new instance of FileReader.
42 43 44 |
# File 'lib/soxer/main.rb', line 42 def initialize filename, settings @f, @s = filename, settings end |
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
40 41 42 |
# File 'lib/soxer/main.rb', line 40 def filename @filename end |
Instance Method Details
#get_content ⇒ Object
The method, that retuns the YAML structure in a ::hashie hash::. Hashie makes the hash keys accessible either strings, symbols or methods.
48 49 50 51 52 53 54 55 |
# File 'lib/soxer/main.rb', line 48 def get_content out = YAML.load_file( @f ) add_date unless out['date'] add_id unless out['uuid'] out['url'] = @f.gsub(/#{@s.origin}(.+)\.yaml$/, "\\1" ).gsub(/(.+)\/index$/, "\\1" ) out['mtime'] = File.mtime( @f ) Hashie::Mash.new out end |