Module: PositiveWebSupport::StringExt
- Defined in:
- lib/positive_web_support/string_ext.rb
WebColor を表す文字列に対するメソッド collapse
-
#is_web_color?(with_sharp: nil) ⇒ Boolean
WebColor の文字列であるか否かを判定するメソッド.
-
#to_rgb_color ⇒ ::Array <Integer (natural number)>
WebColor を RgbColor に変換するメソッド.
- #to_rgb_color_in_parentheses ⇒ Object
Instance Method Summary collapse
-
#hex_string? ⇒ Boolean
16進数の文字列か否かを判定するメソッド.
Instance Method Details
#hex_string? ⇒ Boolean
16進数の文字列か否かを判定するメソッド
5 6 7 |
# File 'lib/positive_web_support/string_ext.rb', line 5 def hex_string? /\A[\da-fA-F]+\Z/ === self end |
#is_web_color?(with_sharp: nil) ⇒ Boolean
WebColor の文字列であるか否かを判定するメソッド
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/positive_web_support/string_ext.rb', line 13 def is_web_color?( with_sharp: nil ) raise "Error" unless with_sharp.nil? or with_sharp.boolean? # nil if with_sharp.nil? is_web_color_without_sharp? or is_web_color_with_sharp? # true elsif with_sharp is_web_color_with_sharp? # false else is_web_color_without_sharp? end end |
#to_rgb_color ⇒ ::Array <Integer (natural number)>
WebColor を RgbColor に変換するメソッド
30 31 32 33 34 35 |
# File 'lib/positive_web_support/string_ext.rb', line 30 def to_rgb_color unless is_web_color? raise "Error" end gsub( /\#/ , "" ).each_char.each_slice(2).map{ | ary | ary.join.hex } end |
#to_rgb_color_in_parentheses ⇒ Object
37 38 39 40 |
# File 'lib/positive_web_support/string_ext.rb', line 37 def to_rgb_color_in_parentheses str = to_rgb_color.join( " , " ) "(#{str})" end |