Class: Gradient::GRD
- Inherits:
-
Object
- Object
- Gradient::GRD
- Defined in:
- lib/gradient/grd.rb
Constant Summary collapse
- COLOR_TERMS =
%w(Cyn Mgnt Ylw Blck Rd Grn Bl H Strt Brgh)
- PARSE_METHODS =
{ "patt" => :parse_patt, "desc" => :parse_desc, "VlLs" => :parse_vlls, "TEXT" => :parse_text, "Objc" => :parse_objc, "UntF" => :parse_untf, "bool" => :parse_bool, "long" => :parse_long, "doub" => :parse_doub, "enum" => :parse_enum, "tdta" => :parse_tdta, }
Instance Attribute Summary collapse
-
#maps ⇒ Object
readonly
Returns the value of attribute maps.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ GRD
constructor
A new instance of GRD.
- #parse(buffer) ⇒ Object
Constructor Details
#initialize ⇒ GRD
Returns a new instance of GRD.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/gradient/grd.rb', line 43 def initialize @maps = {} @gradient_names = [] @color_gradients = [] @transparency_gradients = [] @current_object_name = "" @current_color_gradient = [] @current_transparency_gradient = [] @current_color = {} @current_transparency = {} @shift = 0 end |
Instance Attribute Details
#maps ⇒ Object (readonly)
Returns the value of attribute maps.
19 20 21 |
# File 'lib/gradient/grd.rb', line 19 def maps @maps end |
Class Method Details
.open(file) ⇒ Object
37 38 39 |
# File 'lib/gradient/grd.rb', line 37 def open(file) read(file) end |
.parse(string_buffer) ⇒ Object
23 24 25 26 27 |
# File 'lib/gradient/grd.rb', line 23 def parse(string_buffer) new.tap do |parser| parser.parse(string_buffer) end.maps end |
.read(file) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/gradient/grd.rb', line 29 def read(file) new.tap do |parser| File.open(file, "r") do |file| parser.parse(file.read) end end.maps end |
Instance Method Details
#parse(buffer) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/gradient/grd.rb', line 59 def parse(buffer) @buffer = buffer @offset = 28 parse_entry while @offset < @buffer.length flush_current_gradient color_gradients = @color_gradients.map do |gradient| clean_color_gradient(gradient).map do |color_step| Gradient::ColorPoint.new(*color_step) end end transparency_gradients = @transparency_gradients.map do |gradient| clean_transparency_gradient(gradient).map do |transparency_step| Gradient::OpacityPoint.new(*transparency_step) end end gradients = color_gradients.zip(transparency_gradients).map do |color_points| Gradient::Map.new(Gradient::PointMerger.new(*color_points).call) end @maps = Hash[ @gradient_names.zip(gradients) ] end |