class TokyoMetro::Factory::Generate::Static::Color::Info

Public Class Methods

hash_keys() click to toggle source
# File lib/tokyo_metro/factory/generate/static/color/info.rb, line 23
def self.hash_keys
  hash_keys_of_color
end
hash_keys_of_color() click to toggle source
# File lib/tokyo_metro/factory/generate/static/color/info.rb, line 15
def self.hash_keys_of_color
  [ :web ] + rgb_keys
end
info_class_for_this_class() click to toggle source
# File lib/tokyo_metro/factory/generate/static/color/info.rb, line 11
def self.info_class_for_this_class
  toplevel_class
end
new(h) click to toggle source
# File lib/tokyo_metro/factory/generate/static/color/info.rb, line 5
def initialize(h)
  @h = h.with_indifferent_access
  @hash_for_making_variables = ::Hash.new.with_indifferent_access
  set_values_to_hash_for_making_variables
end
rgb_keys() click to toggle source
# File lib/tokyo_metro/factory/generate/static/color/info.rb, line 19
def self.rgb_keys
  [ :red , :green , :blue ]
end

Private Instance Methods

all_rgb_defined?() click to toggle source

RGB の各成分が正当に定義されているか否かを判定するメソッド @return [Boolean]

# File lib/tokyo_metro/factory/generate/static/color/info.rb, line 58
def all_rgb_defined?
  rgb_array.all? { |i| i.integer? and i >= 0 and i <= 255 }
end
check_validity_of_variables() click to toggle source

WebColor, RGB の各成分が矛盾なく設定されているか否かを確認するメソッド @return [nil]

# File lib/tokyo_metro/factory/generate/static/color/info.rb, line 93
def check_validity_of_variables
  unless rgb_from_web == rgb_array
    str_ary = ::Array.new
    str_ary << "Error:"
    str_ary << "\[webcolor\]"
    str_ary << @hash_for_making_variables[ :web ]
    str_ary << "(#{ rgb_from_web })"
    str_ary << "/"
    str_ary << "\[rgb\]"
    str_ary << rgb_array.map( &:to_s ).join( " , " )
    str_ary << "(#{ web_from_rgb })"

    raise str_ary.map( &:to_s ).join( " " )
  end

  return nil
end
color_variables() click to toggle source
# File lib/tokyo_metro/factory/generate/static/color/info.rb, line 33
def color_variables
  self.class.hash_keys_of_color.map { | key_name | @hash_for_making_variables[ key_name ] }
end
rgb_array() click to toggle source
# File lib/tokyo_metro/factory/generate/static/color/info.rb, line 70
def rgb_array
  self.class.rgb_keys.map { | element | @hash_for_making_variables[ element ] }
end
rgb_from_web() click to toggle source
# File lib/tokyo_metro/factory/generate/static/color/info.rb, line 66
def rgb_from_web
  @hash_for_making_variables[ :web ].to_rgb_color
end
set_rgb() click to toggle source

WebColor の情報をもとに RGB の成分の情報を取得するメソッド

# File lib/tokyo_metro/factory/generate/static/color/info.rb, line 79
def set_rgb
  r , g , b = rgb_from_web
  @hash_for_making_variables[ :red ] = r
  @hash_for_making_variables[ :green ] = g
  @hash_for_making_variables[ :blue ] = b
end
set_values_to_hash_for_making_variables() click to toggle source
# File lib/tokyo_metro/factory/generate/static/color/info.rb, line 37
def set_values_to_hash_for_making_variables
  super

  # web が定義されていて、red, green, blue(の一部)が未定義の場合
  if web_color_defined? and !( all_rgb_defined? )
    set_rgb

 # red, green, blue がすべて定義されていて、web が定義されていない場合
  elsif !( web_color_defined? ) and all_rgb_defined?
    set_web

  # web, red, green, blue がすべて定義されている場合
  elsif web_color_defined? and all_rgb_defined?
    check_validity_of_variables
  else
    raise "Error"
  end
end
set_web() click to toggle source

RGB の成分の情報をもとに WebColor の情報を取得するメソッド

# File lib/tokyo_metro/factory/generate/static/color/info.rb, line 87
def set_web
  @hash_for_making_variables[ :web ] = web_from_rgb
end
variables() click to toggle source
# File lib/tokyo_metro/factory/generate/static/color/info.rb, line 29
def variables
  color_variables
end
web_color_defined?() click to toggle source
# File lib/tokyo_metro/factory/generate/static/color/info.rb, line 62
def web_color_defined?
  @hash_for_making_variables[ :web ].present?
end
web_from_rgb() click to toggle source
# File lib/tokyo_metro/factory/generate/static/color/info.rb, line 74
def web_from_rgb
  "\#" + rgb_array.map( &:to_two_digit_hex ).join
end