Class: Frameit::Offsets
- Inherits:
-
Object
- Object
- Frameit::Offsets
- Defined in:
- frameit/lib/frameit/offsets.rb
Class Method Summary collapse
-
.image_offset(screenshot) ⇒ Object
Returns the image offset needed for a certain device type.
- .sanitize_device_name(basename) ⇒ Object
Class Method Details
.image_offset(screenshot) ⇒ Object
Returns the image offset needed for a certain device type
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'frameit/lib/frameit/offsets.rb', line 7 def self.image_offset(screenshot) require 'json' unless @offsets_cache offsets_json_path = File.join(FrameDownloader.new.templates_path, "offsets.json") UI.user_error!("Could not find offsets.json file at path '#{offsets_json_path}'") unless File.exist?(offsets_json_path) @offsets_cache = JSON.parse(File.read(offsets_json_path)) end offset_value = @offsets_cache["portrait"][sanitize_device_name(screenshot.device_name)] UI.error("Tried looking for offset information for 'portrait', #{screenshot.device_name} in '#{offsets_json_path}'") unless offset_value return offset_value end |
.sanitize_device_name(basename) ⇒ Object
21 22 23 24 25 26 |
# File 'frameit/lib/frameit/offsets.rb', line 21 def self.sanitize_device_name(basename) # this should be the same as frames_generator's sanitize_device_name (except stripping colors): basename = basename.gsub("Apple", "") basename = basename.gsub("-", " ") basename.strip.to_s end |