Class: Sinatra::Soxer::FileReader

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#filenameObject

Returns the value of attribute filename.



40
41
42
# File 'lib/soxer/main.rb', line 40

def filename
  @filename
end

Instance Method Details

#get_contentObject

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