class Wetter

#

require 'wetter/constants.rb'

#
#

require 'wetter/menu.rb'

#
#

require 'wetter/toplevel_methods/is_on_roebe.rb'

#

Constants

N
#

N

#
TRY_TO_MAKE_USE_OF_THE_UNICODE_WEATHER_SYMBOL
#

TRY_TO_MAKE_USE_OF_THE_UNICODE_WEATHER_SYMBOL

If the next constant is set to true then class Wetter will try to make use of the unicode symbol for “cloudy weather”.

#
URL
#

URL

Point to the remote website that holds the information for the local temperature in the city of Vienna.

#
USE_DEGREE_REGEX
#

USE_DEGREE_REGEX

This second regex can be used when we wish to match against &deg values.

#
USE_THIS_REGEX
#

USE_THIS_REGEX

#

Public Class Methods

current_degrees() click to toggle source
#

Wetter.current_degrees

This method will simply return a Float number, the current temperature in Vienna by default.

#
# File lib/wetter/wetter.rb, line 226
def self.current_degrees
  Wetter.new { :be_silent }.match?.to_f
end
is_on_roebe?() click to toggle source
#

Wetter.is_on_roebe?

#
# File lib/wetter/toplevel_methods/is_on_roebe.rb, line 12
def self.is_on_roebe?
  ENV['IS_ROEBE'].to_s == '1'
end
menu(i) click to toggle source
#

Wetter.menu (menu tag)

#
new( optional_commandline_arguments = ARGV, run_already = true ) { || ... } click to toggle source
#

initialize

#
# File lib/wetter/wetter.rb, line 33
def initialize(
    optional_commandline_arguments = ARGV,
    run_already                    = true
  )
  reset
  if block_given?
    yielded = yield
    case yielded
    when :be_silent
      @be_verbose = false
    end
  end
  if optional_commandline_arguments
    menu(optional_commandline_arguments)
  end
  run if run_already
end
run( i = ARGV ) click to toggle source
#

Wetter.run

#
# File lib/wetter/wetter.rb, line 214
def self.run(
    i = ARGV
  )
  self.new(i)
end
start_sinatra_interface() click to toggle source
#

Wetter.start_sinatra_interface

This method can be used to start the sinatra interface.

#
# File lib/wetter/www/start_sinatra_interface.rb, line 18
def self.start_sinatra_interface
  puts 'Trying to start the sinatra-interface for class Wetter next.'
  ::Wetter::Sinatra.run!
end

Public Instance Methods

cliner() click to toggle source
#

cliner

#
# File lib/wetter/wetter.rb, line 76
def cliner
  '=' * 80
end
debug?() click to toggle source
#

debug?

#
# File lib/wetter/wetter.rb, line 69
def debug?
  @debug
end
enable_debug_mode() click to toggle source
#

enable_debug_mode

#
# File lib/wetter/wetter.rb, line 62
def enable_debug_mode
  @debug = true
end
find_match() click to toggle source
#

find_match

#
# File lib/wetter/wetter.rb, line 105
def find_match
  @data  =~ USE_THIS_REGEX
  @match = $1.to_s.dup
end
match?() click to toggle source
#

match?

#
# File lib/wetter/wetter.rb, line 113
def match?
  @match
end
menu(i) click to toggle source
#

menu (menu tag)

#
read_in_dataset_from_remote_webpage() click to toggle source
#

read_in_dataset_from_remote_webpage

#
# File lib/wetter/wetter.rb, line 190
def read_in_dataset_from_remote_webpage
  @data = URI.open(URL).read
  if debug?
    opn; e 'Now showing @data, as we run in @debug mode.'
    e cliner
    e @data
    e cliner
  end
  return @data
end
report_result() click to toggle source
#

report_result

#
# File lib/wetter/wetter.rb, line 150
def report_result
  if @be_verbose
    n_degrees_celsius = match?.to_f
    result = "The current temperature in Vienna is: "\
             "#{sfancy(n_degrees_celsius)} °C".dup
    if try_to_make_use_of_the_unicode_weather_symbol?
      begin
        require 'roebe/toplevel_methods/unicode/popular_unicode_symbols.rb'
        case n_degrees_celsius
        when 16..50 # Should be clear weather most of the time.
          result << " #{tomato(Roebe.clear_weather)}"
        when 5..15 # Medium-temperature; usually cloudy.
          result << " #{royalblue(Roebe.cloudy_weather_symbol)}"
        when -30..4 # It's really quite cold.
          result << " #{royalblue(Roebe.snowman)}"
        end
      rescue LoadError
      end
    end
    opn; e result
  end
end
reset() click to toggle source
#

reset (reset tag)

#
# File lib/wetter/wetter.rb, line 54
def reset
  @debug = false
  @be_verbose = true
end
royalblue(i = '') click to toggle source
#

royalblue

#
# File lib/wetter/wetter.rb, line 176
def royalblue(i = '')
  Colours.royalblue(i)
end
run() click to toggle source
#

run (run tag)

#
# File lib/wetter/wetter.rb, line 204
def run
  read_in_dataset_from_remote_webpage
  sanitize_dataset
  find_match
  report_result
end
sanitize_dataset() click to toggle source
#

sanitize_dataset

#
# File lib/wetter/wetter.rb, line 83
def sanitize_dataset
  splitted = @data.split(N)
  splitted.reject! {|line|
    ! (line.include?('title="Wien Innere Stadt') and line.include?('Temp: '))
  }
  splitted = splitted.first if splitted.is_a? Array
  if debug?
    opn; e 'Now showing the sanitized dataset, as we run in @debug mode.'
    pp splitted
  end
  @data = splitted
  if @data.nil?
    @data =~ USE_DEGREE_REGEX
    unless $1.to_s.dup.empty?
      @data = $1.to_s.dup
    end
  end
end
show_help() click to toggle source
#

show_help

#
# File lib/wetter/wetter.rb, line 120
def show_help
  e
  e '  --URL # show the remote URL'
  e
end
show_the_remote_url() click to toggle source
#

show_the_remote_url

To invoke this method, do:

wetter --URL
#
# File lib/wetter/wetter.rb, line 134
def show_the_remote_url
  e
  e sfancy("  #{URL}")
  e
end
tomato(i = '') click to toggle source
#

tomato

#
# File lib/wetter/wetter.rb, line 183
def tomato(i = '')
  Colours.tomato(i)
end
try_to_make_use_of_the_unicode_weather_symbol?() click to toggle source
#

try_to_make_use_of_the_unicode_weather_symbol?

#
# File lib/wetter/wetter.rb, line 143
def try_to_make_use_of_the_unicode_weather_symbol?
  TRY_TO_MAKE_USE_OF_THE_UNICODE_WEATHER_SYMBOL
end