Class: RubyJard::LayoutPicker

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

Overview

Pick layout smartly depending on current window height and width

Instance Method Summary collapse

Constructor Details

#initialize(width, height, layouts: RubyJard::Layouts, config: RubyJard.config) ⇒ LayoutPicker

Returns a new instance of LayoutPicker.



7
8
9
10
11
12
# File 'lib/ruby_jard/layout_picker.rb', line 7

def initialize(width, height, layouts: RubyJard::Layouts, config: RubyJard.config)
  @width = width
  @height = height
  @layouts = layouts
  @config = config
end

Instance Method Details

#pickObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ruby_jard/layout_picker.rb', line 14

def pick
  unless @config.layout.nil?
    return @layouts[@config.layout] || @layouts.fallback_layout
  end

  @layouts.each do |_name, template|
    matched = true
    matched &&= (
      template.min_width.nil? ||
      @width > template.min_width
    )
    matched &&= (
      template.min_height.nil? ||
      @height > template.min_height
    )
    return template if matched
  end
  @layouts.fallback_layout
end