Module: Glib::EnumHelper
- Included in:
- JsonUi::ViewBuilder::Fields::TimeZone
- Defined in:
- app/helpers/glib/enum_helper.rb
Instance Method Summary collapse
- #glib_enum_options(clazz, enum_field, keys: nil, hint_suffix: false, hint_subtitle: false) ⇒ Object
-
#glib_time_zone_options ⇒ Object
See en.wikipedia.org/wiki/List_of_tz_database_time_zones and description.
Instance Method Details
#glib_enum_options(clazz, enum_field, keys: nil, hint_suffix: false, hint_subtitle: false) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'app/helpers/glib/enum_helper.rb', line 3 def (clazz, enum_field, keys: nil, hint_suffix: false, hint_subtitle: 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, hint_suffix: hint_suffix) option = { text: text, value: i } if hint_subtitle && (hint = clazz.glib_enum_hint(enum_field, i)) option[:subtitle] = hint end option end end |
#glib_time_zone_options ⇒ Object
See en.wikipedia.org/wiki/List_of_tz_database_time_zones and description
17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/helpers/glib/enum_helper.rb', line 17 def # For some reason, some offsets differ on some machines causing test failures. # TZInfo::Timezone.default_dst = true return [] if Rails.env.test? ActiveSupport::TimeZone.all.group_by { |tz| tz.tzinfo.identifier }.map do |identifier, timezones| utc_offset = "#{timezones.first.utc_offset >= 0 ? '+' : ''}#{timezones.first.utc_offset / 60 / 60}h" locations = timezones.map(&:name).join(', ') { value: identifier, text: "#{utc_offset} #{locations}" } end end |