Class: Cyberweb::Calculator
- Inherits:
-
Base
- Object
- Base
- Cyberweb::Calculator
show all
- Defined in:
- lib/cyberweb/standalone_classes/calculator.rb
Overview
Constant Summary
Constants inherited
from Base
Base::HOME_DIRECTORY_OF_THE_USER_X, Base::NAMESPACE
Class Method Summary
collapse
-
.[](i = ARGV) ⇒ Object
# === Cyberweb::Calculator[] ========================================================================= #.
Instance Method Summary
collapse
Methods inherited from Base
#be_verbose, #be_verbose?, #cascading_style_sheets_directory?, #cd, #commandline_mode?, #copyright?, #css_comment, #delete_directory, #do_toggle, #e, #echo_raw, #filename?, #full_path_to_image_directory?, #html_colours?, #html_image, #htmlentities, #img_dir?, #infer_the_namespace, #initialize_the_configuration, #is_a_file?, #is_a_video_file?, #is_an_image_file?, #is_on_roebe?, #last_tag_used?, #last_tag_used_first_element?, #last_tag_used_id?, #mkdir, #mode?, #namespace?, #open_in_browser, #opne, #opnn, #remove_comments_from_this_string_but_preserve_CSS_rules, #remove_html, #return_all_directories, #return_date, #return_program_name, #return_pwd, #ruby_header?, #server_base_directory?, #set_commandline_mode, #set_last_tag_used, #update_the_image_directory, #use_this_relative_directory_for_custom_images?, #www_mode?
#copy_this_file, #cpr, #delete_file, #filename_without_extension?, #read_file_via_utf8_encoding
Methods included from BaseModule
#attach_these_constants, #base_dir?, #beautiful_url, #cd, #create_the_internal_hash, #doctype?, #ee, #ensure_main_encoding, #esystem, #html_templates, #initialize_the_config_if_the_config_hash_is_empty, #internal_hash?, #log_dir?, #no_http, #random_alphabet_characters, #rarrow?, #rds, #remove_comments_from_this_string, #remove_numbers, #require_the_html_templates, #require_these, #return_file_size_in_kb_of, #return_html_comment, #ruby_sitelib_dir?, #sanitize_this_id, #server_base_directory?, #string_remote_image, #today?, #try_to_require_rack, #try_to_require_the_open_gem, #write_what_into
#content_type_is_html, #content_type_is_jpeg, #content_type_is_json, #content_type_is_plain_text
#append_to_the_commandline_arguments, #commandline_arguments?, #first_argument?, #parse_these_commandline_arguments, #second_argument?, #set_commandline_arguments
#all_html_colours, #lightgreen, #rev, #sdir, #sfancy, #sfile, #simp, #steelblue, #tomato
Constructor Details
#initialize(commandline_arguments = nil, run_already = true, &block) ⇒ Calculator
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/cyberweb/standalone_classes/calculator.rb', line 23
def initialize(
commandline_arguments = nil,
run_already = true,
&block
)
reset
set_work_on_this_input(
commandline_arguments
)
if block_given?
yielded = yield
case yielded
when :report_the_result_on_the_commandline
@report_result = true
end
end
run if run_already
end
|
Class Method Details
.[](i = ARGV) ⇒ Object
#
Cyberweb::Calculator[]
#
127
128
129
|
# File 'lib/cyberweb/standalone_classes/calculator.rb', line 127
def self.[](i = ARGV)
new(i)
end
|
Instance Method Details
112
113
114
|
# File 'lib/cyberweb/standalone_classes/calculator.rb', line 112
def report
puts @result
end
|
49
50
51
52
53
54
55
|
# File 'lib/cyberweb/standalone_classes/calculator.rb', line 49
def reset
super()
@report_result = false
end
|
#result? ⇒ Boolean
98
99
100
|
# File 'lib/cyberweb/standalone_classes/calculator.rb', line 98
def result?
@result
end
|
119
120
121
122
|
# File 'lib/cyberweb/standalone_classes/calculator.rb', line 119
def run
silently_calculate_the_result
report if @report_result
end
|
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/cyberweb/standalone_classes/calculator.rb', line 69
def sanitize_input
@work_on_this_input.gsub!(/[A-Za-z]/,'')
if @work_on_this_input.include?('/')
try_to_find_this_index = @work_on_this_input.index(/\d\//)
if try_to_find_this_index
unless @work_on_this_input.include? '.0/'
@work_on_this_input[try_to_find_this_index+1,0] = '.0'
end
end
end
end
|
60
61
62
63
64
|
# File 'lib/cyberweb/standalone_classes/calculator.rb', line 60
def set_work_on_this_input(i = '')
i = [i].flatten.compact.first
@work_on_this_input = i.dup
sanitize_input
end
|
#silently_calculate_the_result ⇒ Object
#
silently_calculate_the_result
This method will silently calculate the result. Another method can be used to report said result, e. g. on the commandline.
#
91
92
93
|
# File 'lib/cyberweb/standalone_classes/calculator.rb', line 91
def silently_calculate_the_result
@result = eval(input?)
end
|
105
106
107
|
# File 'lib/cyberweb/standalone_classes/calculator.rb', line 105
def work_on_this_input?
@work_on_this_input
end
|