Last active
October 31, 2015 14:45
-
-
Save hachy/d06d8d0512311b1a2622 to your computer and use it in GitHub Desktop.
nogizaka_blog example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# gem install nogizaka_blog | |
# https://github.com/hachy/nogizaka_blog | |
require 'optparse' | |
require 'nogizaka_blog' | |
def run | |
ym = @nogi.yearmonth | |
puts "#{ym[0..3]}/#{ym[4..5]}" | |
header = display_format('name', 'comment', 'article') | |
puts header | |
puts '-' * header.size | |
@nogi.each do |name, comment, article| | |
puts display_format("#{name.to_kanji}(#{name})", comment, article) | |
end | |
end | |
def display_format(name, comment, article) | |
name_length = 28 - full_width_count(name) | |
[name.ljust(name_length), comment.to_s.rjust(7), article.to_s.rjust(7)].join(' | ') | |
end | |
def full_width_count(string) | |
string.each_char.select { |char| !(/[ -~。-゚]/.match(char)) }.count | |
end | |
OptionParser.new do |opt| | |
opt.banner = 'Usage: ruby nogizaka_cli.rb -y 201404' | |
opt.on('-y [yearmonth]', 'specify the month you want to get. ex. 201404') do |yearmonth| | |
@nogi = NogizakaBlog::Amazing.new(yearmonth) | |
run | |
end | |
opt.on_tail('-v', '--version', 'Show version') do | |
puts "NogizakaBlog #{NogizakaBlog::VERSION}" | |
exit | |
end | |
opt.parse!(ARGV) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment