Class: Hootenanny::Feed::File

Inherits:
Object
  • Object
show all
Defined in:
lib/hootenanny/feed/file.rb

Constant Summary collapse

FILE_EXTENSION_MAPPINGS =
{
  '.rss'    => 'RSS',
  '.atom'   => 'Atom',
  '.json'   => 'JSON',
  '.digest' => 'Digest',
}

Instance Method Summary collapse

Constructor Details

#initialize(base_path) ⇒ File

Returns a new instance of File.



13
14
15
# File 'lib/hootenanny/feed/file.rb', line 13

def initialize(base_path)
  self.path = base_path
end

Instance Method Details

#<<(other_path) ⇒ Object



17
18
19
20
21
# File 'lib/hootenanny/feed/file.rb', line 17

def <<(other_path)
  return self if other_path.nil? || other_path == ''

  self.class.new(path + other_path)
end

#readObject



23
24
25
# File 'lib/hootenanny/feed/file.rb', line 23

def read
  file.exist? ? file.read : ''
end

#to_sObject



39
40
41
# File 'lib/hootenanny/feed/file.rb', line 39

def to_s
  file.to_s
end

#typeObject



35
36
37
# File 'lib/hootenanny/feed/file.rb', line 35

def type
  FILE_EXTENSION_MAPPINGS[extension]
end

#write(content) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/hootenanny/feed/file.rb', line 27

def write(content)
  path.dirname.mkpath

  path.open('w+') do |f|
    f.write(content)
  end
end