class NogizakaBlog::CLI

Constants

GLYPHS

Public Instance Methods

when(yearmonth) click to toggle source
# File lib/nogizaka_blog/cli.rb, line 11
def when(yearmonth)
  @nogi = Amazing.new(yearmonth)
  print_header
  spinner
  case options[:sort]
  when 'comment' then sort_by_comment
  when 'article' then sort_by_article
  else normal
  end
end

Private Instance Methods

display_format(name, comment, article) click to toggle source
# File lib/nogizaka_blog/cli.rb, line 61
def display_format(name, comment, article)
  name_length = 10 - full_width_count(name)
  [name.ljust(name_length), comment.to_s.rjust(7), article.to_s.rjust(7)].join(' | ')
end
full_width_count(string) click to toggle source
# File lib/nogizaka_blog/cli.rb, line 66
def full_width_count(string)
  string.each_char.count { |char| !(/[ -~。-゚]/.match(char)) }
end
normal() click to toggle source
# File lib/nogizaka_blog/cli.rb, line 43
def normal
  @nogi.each do |name, comment, article|
    puts display_format("#{name.to_kanji}", comment, article)
  end
end
print_header() click to toggle source
sort_by_article() click to toggle source
# File lib/nogizaka_blog/cli.rb, line 55
def sort_by_article
  @nogi.sort_by { |_, _, c| c }.reverse_each do |name, comment, article|
    puts display_format("#{name.to_kanji}", comment, article)
  end
end
sort_by_comment() click to toggle source
# File lib/nogizaka_blog/cli.rb, line 49
def sort_by_comment
  @nogi.sort_by { |_, b, _| b }.reverse_each do |name, comment, article|
    puts display_format("#{name.to_kanji}", comment, article)
  end
end
spinner() click to toggle source
# File lib/nogizaka_blog/cli.rb, line 32
def spinner
  Thread.new do
    loop do
      GLYPHS.each do |glyph|
        print "processing.. #{glyph}\r"
        sleep 0.15
      end
    end
  end
end