Module: ChemistryParadise::GUI::TemperatureConverterModule

Included in:
Gtk::TemperatureConverter, LibUI::TemperatureConverter
Defined in:
lib/chemistry_paradise/gui/shared_code/temperature_converter/temperature_converter_module.rb

Overview

ChemistryParadise::GUI::TemperatureConverterModule

Constant Summary collapse

NAMESPACE =
#

NAMESPACE

#
inspect
TITLE =
#

TITLE

#
'Temperature Converter'
WIDTH =
#

WIDTH

#
'35% or minimum 540px'
HEIGHT =
#

HEIGHT

#
'20% or minimum 250px'
USE_THIS_FONT =
#

USE_THIS_FONT

#
:dejavu_condensed_22

Instance Method Summary collapse

Instance Method Details

#border_size?Boolean

#

border_size?

#

Returns:

  • (Boolean)


62
63
64
# File 'lib/chemistry_paradise/gui/shared_code/temperature_converter/temperature_converter_module.rb', line 62

def border_size?
  0
end

#calculate_celsius_and_set_the_correct_value(i = @entry_fahrenheit.text?) ⇒ Object

#

calculate_celsius_and_set_the_correct_value

#


120
121
122
123
124
125
# File 'lib/chemistry_paradise/gui/shared_code/temperature_converter/temperature_converter_module.rb', line 120

def calculate_celsius_and_set_the_correct_value(
    i = @entry_fahrenheit.text?
  )
  i = ChemistryParadise::FahrenheitToCelsius.new(i).celsius?.to_s.delete('`').to_f.round(2).to_s
  @entry_celsius.set_text(i.to_s)
end

#calculate_fahrenheit_and_set_the_correct_value(i = @entry_celsius.text?) ⇒ Object

#

calculate_fahrenheit_and_set_the_correct_value

This is the to_fahrenheit conversion.

#


153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/chemistry_paradise/gui/shared_code/temperature_converter/temperature_converter_module.rb', line 153

def calculate_fahrenheit_and_set_the_correct_value(
    i = @entry_celsius.text?
  )
  # ======================================================================= #
  # Also set the value of n Kelvin.
  # ======================================================================= #
  @entry_kelvin.set_text(
    return_n_kelvin(i).to_s.to_f.round(2).to_s
  )
  i = ChemistryParadise::CelsiusToFahrenheit.new(i).fahrenheit?
  @entry_fahrenheit.set_text(i.to_s)
end

#calculate_kelvin_and_set_the_correct_value(i = @entry_celsius.text?) ⇒ Object

#

calculate_kelvin_and_set_the_correct_value

#


130
131
132
133
134
135
# File 'lib/chemistry_paradise/gui/shared_code/temperature_converter/temperature_converter_module.rb', line 130

def calculate_kelvin_and_set_the_correct_value(
    i = @entry_celsius.text?
  )
  i = ChemistryParadise.kelvin(i)
  @entry_celsius.set_text(i.to_s)
end

#create_the_entriesObject

#

create_the_entries (entries tag, entry tag)

#


69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/chemistry_paradise/gui/shared_code/temperature_converter/temperature_converter_module.rb', line 69

def create_the_entries
  # ======================================================================= #
  # === @entry_celsius
  # ======================================================================= #
  @entry_celsius = entry
  @entry_celsius.center
  @entry_celsius.yellow_background
  # @entry_celsius.accept_only_numbers_as_input
  @entry_celsius.on_enter {
    calculate_fahrenheit_and_set_the_correct_value
  }
  callback = proc { |ptr|
    last_character = @entry_celsius.text?[-1, 1]
    case last_character
    when /\d+/ # is a number
      calculate_fahrenheit_and_set_the_correct_value
    when nil, ''
      set_all_entries_to('')
    end  
  }
  @entry_celsius.on_changed { callback }
  # ======================================================================= #
  # === @entry_fahrenheit
  # ======================================================================= #
  @entry_fahrenheit = entry
  @entry_fahrenheit.center
  @entry_fahrenheit.yellow_background
  @entry_fahrenheit.on_enter {
    calculate_celsius_and_set_the_correct_value
  }
  # ======================================================================= #
  # === @entry_kelvin
  # ======================================================================= #
  @entry_kelvin = entry
  @entry_kelvin.center
  @entry_kelvin.yellow_background
  @entry_kelvin.on_enter {
    calculate_kelvin_and_set_the_correct_value
  }
  # ======================================================================= #
  # Style the various entries next in an uniform manner.
  # ======================================================================= #
  return_all_entries.each {|this_entry|
    this_entry.bblack1
    this_entry.width_height(350, 44)
  }
end

#create_the_gridObject

#

create_the_grid

#


183
184
185
186
187
188
189
190
# File 'lib/chemistry_paradise/gui/shared_code/temperature_converter/temperature_converter_module.rb', line 183

def create_the_grid
  # ======================================================================= #
  # === @grid
  # ======================================================================= #
  @grid = grid { :default }
  @grid.pad10px
  @grid.spacing = 8
end

#padding?Boolean

#

padding?

#

Returns:

  • (Boolean)


55
56
57
# File 'lib/chemistry_paradise/gui/shared_code/temperature_converter/temperature_converter_module.rb', line 55

def padding?
  8
end

#reset_the_shared_moduleObject

#

reset_the_shared_module

#


48
49
50
# File 'lib/chemistry_paradise/gui/shared_code/temperature_converter/temperature_converter_module.rb', line 48

def reset_the_shared_module
  title_width_height_font(TITLE, WIDTH, HEIGHT, USE_THIS_FONT)
end

#return_n_kelvin(i = @entry_celsius.text?) ⇒ Object

#

return_n_kelvin

#


140
141
142
143
144
145
146
# File 'lib/chemistry_paradise/gui/shared_code/temperature_converter/temperature_converter_module.rb', line 140

def return_n_kelvin(
    i = @entry_celsius.text?
  )
  result = ChemistryParadise.kelvin(i)
  result = 0 if result.to_f < 0 # Kelvin can never be below 0.
  return result
end

#return_the_title_as_labelObject

#

return_the_title_as_label

#


176
177
178
# File 'lib/chemistry_paradise/gui/shared_code/temperature_converter/temperature_converter_module.rb', line 176

def return_the_title_as_label
  left_aligned_bold_label(TITLE)
end

#set_all_entries_to(i = '') ⇒ Object

#

set_all_entries_to

#


169
170
171
# File 'lib/chemistry_paradise/gui/shared_code/temperature_converter/temperature_converter_module.rb', line 169

def set_all_entries_to(i = '')
  return_all_entries.each {|this_entry| this_entry.set_text(i.to_s) }
end