class Stylegen::Data

Public Class Methods

new(data) click to toggle source
# File lib/stylegen/data.rb, line 9
def initialize(data)
  @data = data
end

Public Instance Methods

access_level() click to toggle source
# File lib/stylegen/data.rb, line 41
def access_level
  @data["access_level"] || "internal"
end
basename() click to toggle source
# File lib/stylegen/data.rb, line 37
def basename
  File.basename(@data["output_path"])
end
colors() click to toggle source
# File lib/stylegen/data.rb, line 49
def colors
  @colors ||= @data["colors"].map do |key, value|
    [inflector.camelize_lower(key), generate_color(value)]
  end
end
inflector() click to toggle source
# File lib/stylegen/data.rb, line 13
def inflector
  @inflector ||= Dry::Inflector.new
end
output_path() click to toggle source
# File lib/stylegen/data.rb, line 29
def output_path
  @data["output_path"]
end
struct_name() click to toggle source
# File lib/stylegen/data.rb, line 45
def struct_name
  "#{system_name}Color"
end
swiftui?() click to toggle source
# File lib/stylegen/data.rb, line 33
def swiftui?
  @data["swiftui"] || false
end
system_name() click to toggle source
# File lib/stylegen/data.rb, line 21
def system_name
  @data["system_name"] || "Theme"
end
util_method_name() click to toggle source
# File lib/stylegen/data.rb, line 25
def util_method_name
  inflector.camelize_lower(inflector.underscore(system_name))
end
version() click to toggle source
# File lib/stylegen/data.rb, line 17
def version
  Stylegen::VERSION
end

Private Instance Methods

generate_color(data) click to toggle source
# File lib/stylegen/data.rb, line 57
def generate_color(data)
  if data.is_a?(String)
    Color.from_hex(data)
  elsif data.key?("color")
    Color.from_hex(data["color"], data["alpha"])
  elsif data.key?("light")
    LightDarkColor.new(
      generate_color(data["light"]),
      generate_color(data["dark"])
    )
  elsif data.key?("base")
    BaseElevatedColor.new(
      generate_color(data["base"]),
      generate_color(data["elevated"])
    )
  end
end