Class: Resper::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/resper.rb

Constant Summary collapse

@@ANDROID_SCALES =
[
  {s: 1.0, d: 160, o: 'mdpi'},
  {s: 1.5, d: 240, o: 'hdpi'},
  {s: 2.0, d: 320, o: 'xhdpi'},
  {s: 3.0, d: 480, o: 'xxhdpi'},
  {s: 4.0, d: 640, o: 'xxxhdpi'},
]
@@IOS_UNIVERSAL_SCALES =
[
  {s: 1.0, d: 160, o: ''},
  {s: 2.0, d: 320, o: '@2x'},
  {s: 3.0, d: 480, o: '@3x'},
]

Instance Method Summary collapse

Constructor Details

#initialize(type, input, width, height, output, format) ⇒ Parser

Returns a new instance of Parser.



32
33
34
35
36
37
38
39
# File 'lib/resper.rb', line 32

def initialize type, input, width, height, output, format
  @type = type
  @input = input
  @width = width
  @height = height
  @output = output
  @format = format
end

Instance Method Details

#parse_resources!Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/resper.rb', line 41

def parse_resources!
  if @type == :all || @type == :android
   @@ANDROID_SCALES.each do |scale|
		file = for_android w: scale[:s]*@width, h: scale[:s]*@height,
   d: scale[:d], o: "drawable-#{scale[:o]}"
		reduce_size file
   end
  end

  if @type == :all || @type == :ios
   @@IOS_UNIVERSAL_SCALES.each do |scale|
		file = for_ios scale[:s], scale[:o], scale[:d]
		reduce_size file
   end
   generate_universal_contents 
  end
  if @type == :all || @type == :reactive
   @@IOS_UNIVERSAL_SCALES.each do |scale|
		file = for_reactive scale[:s], scale[:o], scale[:d]
		reduce_size file
   end
  end

end