Sha256: 64319b91d4c531ee2d211d083587ec1b2373760c2ace31256aca60050726cc93

Contents?: true

Size: 1.62 KB

Versions: 2

Compression:

Stored size: 1.62 KB

Contents

# coding: utf-8

require 'thor'
require 'date'
require 'active_support/time'

module Furichan
  class CLI < Thor
    default_command ':furi-chan'

    desc 'furi-chan', 'Do the all of week task'
    def furi_chan
      invoke :init
      invoke :furik
    end

    desc 'init', 'initialize of week setting'
    def init
      wmonth = Time.now().strftime('%Y-%m-') + week_of_month
      sh "git checkout -b #{wmonth}"
      sh "mkdir -p #{wmonth}"
      sh "cp template.md #{wmonth}/README.md"
    end

    desc 'furik', 'this week"s furik'
    def furik
      wmonth = Time.now().strftime('%Y-%m-') + week_of_month
      dest = Pathname(wmonth + '/README.md')
      dest.open('w') { |f| f.puts furik_init }
    end

    private

    def week_of_month
      today = Date.today()
      beginning_of_month = today.beginning_of_month
      cweek = today.cweek - beginning_of_month.cweek

      # It should be first week.
      # Don't add when begining of month is saturday or sunday
      # ex 2017/07/07(Fri) -> 1
      unless beginning_of_month.saturday? or beginning_of_month.sunday?
        cweek += 1
      end

      cweek.to_s
    end

    def furik_init
      week = Date.today.beginning_of_week
      furik = Furik::Cli.new
      furik.options = {
        gh: true,
        ghe: true,
        from: week.to_s,
        to: week.end_of_week.to_s,
        since: 0,
      }
      activity = capture_stdout { furik.activity }
      activity.gsub!('7days Activities', '## 7days Activity')
    end

    def capture_stdout
      out = StringIO.new
      $stdout = out
      yield
      return out.string
    ensure
      $stdout = STDOUT
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
furichan-0.1.1 lib/furichan/cli.rb
furichan-0.1.0 lib/furichan/cli.rb