class Trackstar::Log
Constants
- CONFIG_FILE_NAME
- DEFAULT_FIELDS
- DEFAULT_FORMATTING
- POSTS_DIR
Attributes
fields[R]
formatting[R]
name[R]
Public Class Methods
new()
click to toggle source
# File lib/trackstar/log.rb, line 12 def initialize @config_yaml = load_config_yaml if @config_yaml['post_fields'] @fields = @config_yaml['post_fields'].transform_keys(&:to_sym).transform_values(&:to_sym) else @fields = DEFAULT_FIELDS end if @config_yaml['post_formatting'] @formatting = @config_yaml['post_formatting'].transform_keys(&:to_sym).transform_values(&:to_sym) else @formatting = DEFAULT_FORMATTING end @name = @config_yaml['log_name'] end
Public Instance Methods
build_post()
click to toggle source
# File lib/trackstar/log.rb, line 27 def build_post new_post = Trackstar::Post.new puts "New Post For #{@name}" puts "#{new_post.values[:date]}" puts "---------------------" new_post.fields.each do |key, casting_method| begin puts "#{key}: " new_post.values[key] = gets.chomp.send(casting_method) rescue => e puts "Sorry, that's not a valid input for #{key}. Let's try this again..." retry end end puts "" new_post end
count_hours(post_list=posts)
click to toggle source
# File lib/trackstar/log.rb, line 66 def count_hours(post_list=posts) post_list.map { |post| post.values[:hours].to_f }.inject(0, :+) end
current_week_hours()
click to toggle source
# File lib/trackstar/log.rb, line 74 def current_week_hours count_hours(current_week_posts) end
current_week_post_count()
click to toggle source
# File lib/trackstar/log.rb, line 62 def current_week_post_count current_week_posts.count end
current_week_posts()
click to toggle source
# File lib/trackstar/log.rb, line 51 def current_week_posts start_of_week_timestamp = DateTime.now.beginning_of_week.to_time.to_i @current_week_posts ||= posts.select { |p| p.values[:timestamp].to_i > start_of_week_timestamp } end
post_count()
click to toggle source
stats methods
# File lib/trackstar/log.rb, line 58 def post_count Dir["#{POSTS_DIR}/*"].count { |file| File.file?(file) } end
posts()
click to toggle source
# File lib/trackstar/log.rb, line 45 def posts @posts ||= Dir["#{POSTS_DIR}/*.md"].sort.map do |file| Trackstar::Post.new(file) end end
total_hours()
click to toggle source
# File lib/trackstar/log.rb, line 70 def total_hours count_hours end
Private Instance Methods
load_config_yaml()
click to toggle source
# File lib/trackstar/log.rb, line 79 def load_config_yaml config_path = File.join(Dir.pwd, CONFIG_FILE_NAME) config = YAML.load_file(config_path) config end