Module: Narou::ServerHelpers
- Defined in:
- lib/web/appserver.rb
Instance Method Summary collapse
-
#build_ruby_version ⇒ Object
Rubyバージョンを構築.
-
#convert_boolean_to_on_off(bool) ⇒ Object
nil true false を nil on off という文字列に変換.
-
#convert_on_off_to_boolean(str) ⇒ Object
フォーム情報の真偽値データを実際のデータに変換.
-
#decorate_tags(tags) ⇒ Object
タグをHTMLで装飾する.
-
#h(text) ⇒ Object
HTMLエスケープヘルパー.
-
#select_valid_novel_ids(ids) ⇒ Object
有効な novel ID だけの配列を生成する ID が指定されなかったか、1件も存在しない場合は nil を返す.
-
#value_to_msg(value) ⇒ Object
与えられたデータが真偽値だった場合、設定画面用に「はい」「いいえ」に変換する 真偽値ではなかった場合、そのまま返す.
Instance Method Details
#build_ruby_version ⇒ Object
Rubyバージョンを構築
35 36 37 38 39 40 41 42 |
# File 'lib/web/appserver.rb', line 35 def build_ruby_version begin `"#{RbConfig.ruby}" -v`.strip rescue config = RbConfig::CONFIG "ruby #{RUBY_VERSION}p#{config["PATCHLEVEL"]} [#{RUBY_PLATFORM}]" end end |
#convert_boolean_to_on_off(bool) ⇒ Object
nil true false を nil on off という文字列に変換
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/web/appserver.rb', line 73 def convert_boolean_to_on_off(bool) case bool when TrueClass "on" when FalseClass "off" else "nil" end end |
#convert_on_off_to_boolean(str) ⇒ Object
フォーム情報の真偽値データを実際のデータに変換
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/web/appserver.rb', line 59 def convert_on_off_to_boolean(str) case str when "on" true when "off" false else nil end end |
#decorate_tags(tags) ⇒ Object
タグをHTMLで装飾する
26 27 28 29 30 |
# File 'lib/web/appserver.rb', line 26 def () .map do |tag| %!<span class="tag label label-#{Command::Tag.get_color(tag)}" data-tag="#{escape_html(tag)}">#{escape_html(tag)}</span>! end.join(" ") end |
#h(text) ⇒ Object
HTMLエスケープヘルパー
87 88 89 |
# File 'lib/web/appserver.rb', line 87 def h(text) Rack::Utils.escape_html(text) end |
#select_valid_novel_ids(ids) ⇒ Object
有効な novel ID だけの配列を生成する ID が指定されなかったか、1件も存在しない場合は nil を返す
48 49 50 51 52 53 54 |
# File 'lib/web/appserver.rb', line 48 def select_valid_novel_ids(ids) return nil unless ids.kind_of?(Array) result = ids.select do |id| id =~ /^\d+$/ end result.empty? ? nil : result end |
#value_to_msg(value) ⇒ Object
与えられたデータが真偽値だった場合、設定画面用に「はい」「いいえ」に変換する 真偽値ではなかった場合、そのまま返す
95 96 97 98 99 100 101 102 103 104 |
# File 'lib/web/appserver.rb', line 95 def value_to_msg(value) case value when TrueClass "はい" when FalseClass "いいえ" else value end end |