Class: Lita::Handlers::OnewheelMoonphase

Inherits:
Handler
  • Object
show all
Defined in:
lib/lita/handlers/onewheel_moonphase.rb

Instance Method Summary collapse

Instance Method Details

#get_data(location) ⇒ Object



29
30
31
32
33
34
# File 'lib/lita/handlers/onewheel_moonphase.rb', line 29

def get_data(location)
  Lita.logger.debug "Getting Moon data for #{location}"
  uri = "https://j8jqi56gye.execute-api.us-west-2.amazonaws.com/prod/moon?loc=#{URI.encode location}"
  Lita.logger.debug uri
  JSON.parse(RestClient.get(uri))
end

#get_location(response) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/lita/handlers/onewheel_moonphase.rb', line 36

def get_location(response)
  location = response.matches[0][0]

  if location.empty?
    location = '45.5230622,-122.6764816'
  end

  location
end

#get_moonmoji(percent_full, phase) ⇒ Object

Next step, determine waxing or waning.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/lita/handlers/onewheel_moonphase.rb', line 47

def get_moonmoji(percent_full, phase)
  moonmoji = ''
  waning = false

  if phase.match /waning/i
    waning = true
  end

  case percent_full.sub('%', '').to_i
    when 0..1
      moonmoji = '🌚'
    when 2..32
      moonmoji = waning ? '🌘' : 'πŸŒ’'
    when 33..62
      moonmoji = phase.match(/last/i) ? 'πŸŒ—' : 'πŸŒ“'
    when 63..90
      moonmoji = waning ? 'πŸŒ–' : 'πŸŒ”'
    when 91..100
      moonmoji = 'πŸŒ•'
  end
  moonmoji
end

#moon(response) ⇒ Object

πŸŒ‘πŸŒ›emoonjis = %w(πŸŒšπŸŒ˜πŸŒ—πŸŒ”πŸŒ•πŸŒ–πŸŒ“πŸŒ’)



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/lita/handlers/onewheel_moonphase.rb', line 14

def moon(response)
  location = get_location(response)

  moon = get_data(location)

  # today = Time.now
  rise_time = Time.parse moon['moondata']['rise']
  set_time = Time.parse moon['moondata']['set']

  reply = "#{get_moonmoji(moon['moondata']['fracillum'], moon['moondata']['curphase'])} Moon phase #{moon['moondata']['fracillum']}, #{moon['moondata']['curphase']}.  "
  reply += "Rise: #{rise_time.strftime("%H:%M")}  Set: #{set_time.strftime('%H:%M')}"
  Lita.logger.debug "Replying with #{reply}"
  response.reply reply
end