Class: MoonInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/meteorologist/moon_info.rb

Constant Summary collapse

EMOJI =

This service is built for the ‘moonPhase’ variable in the DarkSky API where a ‘new’ moon is 0 (0.99, 0, and 0.01) and a ‘full’ moon is 0.5 (0.49 - 0.51)

{
  'new'           => '🌑',
  'crescent'      => '🌒',
  'first quarter' => '🌓',
  'gibbous'       => '🌔',
  'full'          => '🌕',
  'disseminating' => '🌖',
  'last quarter'  => '🌗',
  'balsamic'      => '🌘'
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(cycle_completion) ⇒ MoonInfo

Returns a new instance of MoonInfo.



17
18
19
# File 'lib/meteorologist/moon_info.rb', line 17

def initialize(cycle_completion)
  @cycle_completion = cycle_completion
end

Instance Method Details

#active_elementsObject



58
59
60
61
# File 'lib/meteorologist/moon_info.rb', line 58

def active_elements
  return []
  @active_elements ||= build_active_elements
end

#emojiObject



63
64
65
# File 'lib/meteorologist/moon_info.rb', line 63

def emoji
  EMOJI[phase_name]
end

#illuminationObject



21
22
23
24
25
26
27
28
29
# File 'lib/meteorologist/moon_info.rb', line 21

def illumination
  return 0 if new?
  return 1 if full?
  if waxing?
    ((cycle_completion / 0.48) - 0.01).round(2)
  else
    (1 - ((cycle_completion - 0.51) / 0.48)).round(2)
  end
end

#in_signObject



54
55
56
# File 'lib/meteorologist/moon_info.rb', line 54

def in_sign
  #MoonSignCalculator.calculate(date)
end

#phase_nameObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/meteorologist/moon_info.rb', line 39

def phase_name
  return 'new' if new?
  return 'full' if full?

  if waxing?
    return 'crescent' if crescent?
    return 'first quarter' if quarter?
    return 'gibbous' if gibbous?
  else
    return 'disseminating' if gibbous?
    return 'last quarter' if quarter?
    return 'balsamic' if crescent?
  end
end

#waning?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/meteorologist/moon_info.rb', line 35

def waning?
  cycle_completion.between?(0.51, 0.98)
end

#waxing?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/meteorologist/moon_info.rb', line 31

def waxing?
  cycle_completion.between?(0.02, 0.48)
end