Class: Hootenanny::Feed::File
- Inherits:
-
Object
- Object
- Hootenanny::Feed::File
- 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
- #<<(other_path) ⇒ Object
-
#initialize(base_path) ⇒ File
constructor
A new instance of File.
- #read ⇒ Object
- #to_s ⇒ Object
- #type ⇒ Object
- #write(content) ⇒ Object
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 |
#read ⇒ Object
23 24 25 |
# File 'lib/hootenanny/feed/file.rb', line 23 def read file.exist? ? file.read : '' end |
#to_s ⇒ Object
39 40 41 |
# File 'lib/hootenanny/feed/file.rb', line 39 def to_s file.to_s end |
#type ⇒ Object
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 |