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) ⇒ Object



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

def glib_enum_options(clazz, enum_field, keys = nil)
  # keys ||= clazz.send("#{enum_field}s").keys

  keys ||= clazz.send(enum_field.to_s.pluralize).keys
  keys.map { |i| { text: clazz.glib_enum_humanize(enum_field, i), value: i } }
end

#glib_time_zone_optionsObject



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

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