Module: Glib::EnumHelper

Included in:
JsonUi::ViewBuilder::Fields::TimeZone
Defined in:
app/helpers/glib/enum_helper.rb

Instance Method Summary collapse

Instance Method Details

#glib_enum_options(clazz, enum_field, keys: nil, include_hints: false) ⇒ Object



3
4
5
6
7
8
9
10
# File 'app/helpers/glib/enum_helper.rb', line 3

def glib_enum_options(clazz, enum_field, keys: nil, include_hints: false)
  enum_name = enum_field.to_s
  keys ||= clazz.defined_enums[enum_name].keys
  keys.map do |i|
    text = clazz.glib_enum_humanize(enum_field, i, include_hints: include_hints)
    { text: text, value: i }
  end
end

#glib_time_zone_optionsObject



13
14
15
16
17
18
19
20
# File 'app/helpers/glib/enum_helper.rb', line 13

def glib_time_zone_options
  ActiveSupport::TimeZone.all.sort { |a, b|
    a.utc_offset <=> b.utc_offset
  }.collect { |tz|
    utc_offset = "#{tz.utc_offset >= 0 ? '+' : ''}#{tz.utc_offset / 60 / 60}h"
    { value: tz.tzinfo.identifier, text: "#{utc_offset}  #{tz.name}" }
  }
end