Class: Trackstar::Post
- Inherits:
-
Object
- Object
- Trackstar::Post
- Defined in:
- lib/trackstar/post.rb
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#formatting ⇒ Object
readonly
Returns the value of attribute formatting.
-
#values ⇒ Object
Returns the value of attribute values.
Instance Method Summary collapse
- #file_name ⇒ Object
-
#initialize(path = nil) ⇒ Post
constructor
A new instance of Post.
- #persist! ⇒ Object
- #preview ⇒ Object
- #subject_stub ⇒ Object
Constructor Details
#initialize(path = nil) ⇒ Post
Returns a new instance of Post.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/trackstar/post.rb', line 8 def initialize(path = nil) @log = Trackstar::Log.new @fields = @log.fields @formatting = @log.formatting @values = {} if path load_from_path(path) # note this doesn't load the text of the post else now = Time.now @values[:timestamp] = now.to_i @values[:date] = date_time_format(now) end end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
6 7 8 |
# File 'lib/trackstar/post.rb', line 6 def fields @fields end |
#formatting ⇒ Object (readonly)
Returns the value of attribute formatting.
6 7 8 |
# File 'lib/trackstar/post.rb', line 6 def formatting @formatting end |
#values ⇒ Object
Returns the value of attribute values.
5 6 7 |
# File 'lib/trackstar/post.rb', line 5 def values @values end |
Instance Method Details
#file_name ⇒ Object
30 31 32 |
# File 'lib/trackstar/post.rb', line 30 def file_name "#{@values[:timestamp]}-#{subject_stub}.md" end |
#persist! ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/trackstar/post.rb', line 38 def persist! post_file_path = "#{Trackstar::LogHelper::POSTS_DIR}/#{file_name}" File.open(post_file_path, 'w') do |post_file| post_file.puts "date: #{@values[:date]}" fields.keys.each do |field_name| post_file.puts "#{field_name.to_s}: #{values[field_name]}" if formatting.include? field_name self.send(formatting[field_name], post_file) end end end post_file_path end |
#preview ⇒ Object
24 25 26 27 28 |
# File 'lib/trackstar/post.rb', line 24 def preview @values.each do |key, value| puts "#{key}: #{value}" end end |