Class: Ruboty::Handlers::Rokuyo

Inherits:
Base
  • Object
show all
Defined in:
lib/ruboty/handlers/rokuyo.rb

Instance Method Summary collapse

Constructor Details

#initialize(robot) ⇒ Rokuyo

Returns a new instance of Rokuyo.



9
10
11
12
# File 'lib/ruboty/handlers/rokuyo.rb', line 9

def initialize(robot)
  super(robot)
  @config = JSON.parse File.read(File.dirname(__FILE__) + '/rokuyo.json', encoding: Encoding::UTF_8)
end

Instance Method Details

#description(name) ⇒ Object



47
48
49
50
# File 'lib/ruboty/handlers/rokuyo.rb', line 47

def description(name)
  rokuyo = @config.find{|rokuyo| rokuyo['rokuyo'] == name }
  rokuyo['description']
end

#rokuyo(message) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/ruboty/handlers/rokuyo.rb', line 27

def rokuyo(message)
  time = message[:date] ? Time.parse(message[:date]) : Time.now
  rokuyo = time2rokuyo(time)
  message.reply [
    "#{time.strftime('%Y/%m/%d')}の六曜\☆\n\n",
    "  ====\n  #{rokuyo}\n  ====\n",
    description(rokuyo).gsub(/^/, "  ")
  ].join
end

#taian(message) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/ruboty/handlers/rokuyo.rb', line 37

def taian(message)
  time   = message[:date] ? Time.parse(message[:date]) : Time.now
  rokuyo = time2rokuyo(time)
  until rokuyo == '大安' do
    time += 24 * 60 * 60
    rokuyo = time2rokuyo(time)
  end
  message.reply "★直近の大安★ \n #{time.strftime('%Y/%m/%d')}"
end

#time2rokuyo(time) ⇒ Object



52
53
54
# File 'lib/ruboty/handlers/rokuyo.rb', line 52

def time2rokuyo(time)
  Qreki.calc(time.year, time.month, time.day).rokuyou
end