Class: TiltHydrometer::Beacon

Inherits:
Object
  • Object
show all
Defined in:
lib/tilt_hydrometer/beacon.rb

Instance Method Summary collapse

Constructor Details

#initialize(uuid, temp, gravity) ⇒ Beacon

Returns a new instance of Beacon.



5
6
7
8
9
# File 'lib/tilt_hydrometer/beacon.rb', line 5

def initialize(uuid, temp, gravity)
  @uuid = uuid
  @temp = temp
  @gravity = gravity
end

Instance Method Details

#celsiusObject



46
47
48
49
50
# File 'lib/tilt_hydrometer/beacon.rb', line 46

def celsius
  (
    (temp - 32.0) * (5.0 / 9.0)
  ).round(1)
end

#colorObject



15
16
17
# File 'lib/tilt_hydrometer/beacon.rb', line 15

def color
  TiltHydrometer::DEVICES[@uuid]
end

#gravityObject



27
28
29
30
31
32
33
34
35
# File 'lib/tilt_hydrometer/beacon.rb', line 27

def gravity
  gravity_string = @gravity.to_s

  if pro?
    "#{gravity_string[-5] || 0}.#{gravity_string[-4..-1]}".to_f
  else
    "#{gravity_string[-4] || 0}.#{gravity_string[-3..-1]}".to_f
  end
end

#logObject



56
57
58
59
60
61
62
63
# File 'lib/tilt_hydrometer/beacon.rb', line 56

def log
  LOGGER.debug("Beacon: #{inspect}")
  LOGGER.debug("Temp: #{temp}")
  LOGGER.debug("Celsius: #{celsius}")
  LOGGER.debug("Gravity: #{gravity}")
  LOGGER.debug("Color: #{color}")
  LOGGER.debug("UUID: #{@uuid}")
end

#platoObject



37
38
39
40
41
42
43
44
# File 'lib/tilt_hydrometer/beacon.rb', line 37

def plato
  (
    (-1 * 616.868) +
    (1111.14 * gravity) -
    (630.272 * (gravity**2)) +
    (135.997 * (gravity**3))
  ).round(1)
end

#pro?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/tilt_hydrometer/beacon.rb', line 65

def pro?
  @gravity.to_s[-5] == '1'
end

#tempObject



19
20
21
22
23
24
25
# File 'lib/tilt_hydrometer/beacon.rb', line 19

def temp
  if pro?
    @temp.to_i/10.0
  else
    @temp.to_i
  end
end

#uuidObject



11
12
13
# File 'lib/tilt_hydrometer/beacon.rb', line 11

def uuid
  @uuid
end

#values_out_of_range?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/tilt_hydrometer/beacon.rb', line 52

def values_out_of_range?
  temp > 212 || temp < 1
end