From ef3ecb3bb8e046753c925b6e9d127b1b179032f6 Mon Sep 17 00:00:00 2001 From: Erick Guan <297343+erickguan@users.noreply.github.com> Date: Tue, 5 Mar 2024 21:04:44 +0100 Subject: [PATCH] fixup! Apply linting to source and test code --- lib/ffi-icu/chardet.rb | 4 +- lib/ffi-icu/collation.rb | 10 +- lib/ffi-icu/duration_formatting.rb | 18 ++-- lib/ffi-icu/lib.rb | 160 ++++++++++++++--------------- lib/ffi-icu/locale.rb | 6 +- lib/ffi-icu/normalizer.rb | 4 +- lib/ffi-icu/number_formatting.rb | 14 +-- lib/ffi-icu/time_formatting.rb | 20 ++-- lib/ffi-icu/transliteration.rb | 2 +- spec/break_iterator_spec.rb | 12 ++- spec/duration_formatting_spec.rb | 2 +- spec/locale_spec.rb | 12 ++- spec/number_formatting_spec.rb | 4 +- spec/time_spec.rb | 24 ++--- spec/transliteration_spec.rb | 2 +- 15 files changed, 142 insertions(+), 152 deletions(-) diff --git a/lib/ffi-icu/chardet.rb b/lib/ffi-icu/chardet.rb index 42be959..b49e070 100644 --- a/lib/ffi-icu/chardet.rb +++ b/lib/ffi-icu/chardet.rb @@ -70,14 +70,12 @@ def match_ptr_to_ruby(match_ptr) result end - # rubocop:disable Naming/AccessorMethodName - def set_text(text) + def set_text(text) # rubocop:disable Naming/AccessorMethodName Lib.check_error do |status| data = FFI::MemoryPointer.from_string(text) Lib.ucsdet_setText(@detector, data, text.bytesize, status) end end - # rubocop:enable Naming/AccessorMethodName end end end diff --git a/lib/ffi-icu/collation.rb b/lib/ffi-icu/collation.rb index 4d1170a..bfc5054 100644 --- a/lib/ffi-icu/collation.rb +++ b/lib/ffi-icu/collation.rb @@ -8,7 +8,7 @@ module Collation normalization_mode: 4, strength: 5, hiragana_quaternary_mode: 6, - numeric_collation: 7, + numeric_collation: 7 }.freeze ATTRIBUTE_VALUES = { @@ -27,7 +27,7 @@ module Collation non_ignorable: 21, lower_first: 24, - upper_first: 25, + upper_first: 25 }.freeze ATTRIBUTE_VALUES_INVERSE = ATTRIBUTE_VALUES.to_h { |k, v| [v, k] }.freeze @@ -79,12 +79,12 @@ def compare(a, b) def greater?(a, b) Lib.ucol_greater(@c, UCharPointer.from_string(a), a.jlength, - UCharPointer.from_string(b), b.jlength) + UCharPointer.from_string(b), b.jlength) end def greater_or_equal?(a, b) Lib.ucol_greaterOrEqual(@c, UCharPointer.from_string(a), a.jlength, - UCharPointer.from_string(b), b.jlength) + UCharPointer.from_string(b), b.jlength) end def equal?(*args) @@ -95,7 +95,7 @@ def equal?(*args) a, b = args Lib.ucol_equal(@c, UCharPointer.from_string(a), a.jlength, - UCharPointer.from_string(b), b.jlength) + UCharPointer.from_string(b), b.jlength) end def collate(sortable) diff --git a/lib/ffi-icu/duration_formatting.rb b/lib/ffi-icu/duration_formatting.rb index f3749b0..3bead8e 100644 --- a/lib/ffi-icu/duration_formatting.rb +++ b/lib/ffi-icu/duration_formatting.rb @@ -31,7 +31,7 @@ module DurationFormatting long: :wide, short: :short, narrow: :narrow, - digital: :narrow, + digital: :narrow }.freeze UNIT_FORMAT_STRINGS = { years: 'measure-unit/duration-year', @@ -43,14 +43,14 @@ module DurationFormatting seconds: 'measure-unit/duration-second', milliseconds: 'measure-unit/duration-millisecond', microseconds: 'measure-unit/duration-microsecond', - nanoseconds: 'measure-unit/duration-nanosecond', + nanoseconds: 'measure-unit/duration-nanosecond' }.freeze STYLES_TO_NUMBER_FORMAT_WIDTH = { long: 'unit-width-full-name', short: 'unit-width-short', narrow: 'unit-width-narrow', # digital for hours:minutes:seconds has some special casing. - digital: 'unit-width-narrow', + digital: 'unit-width-narrow' }.freeze def self.format(fields, locale:, style: :long) @@ -75,7 +75,7 @@ def initialize(locale:, style: :long) Lib.check_error do |error| Lib.ulistfmt_openForType(@locale, :units, list_join_format, error) end, - Lib.method(:ulistfmt_close), + Lib.method(:ulistfmt_close) ) end @@ -132,7 +132,7 @@ def hms_duration_units_pattern(fields) @unit_res_bundle ||= FFI::AutoPointer.new( Lib.check_error { |error| Lib.ures_open(Lib.resource_bundle_name(:unit), @locale, error) }, - Lib.method(:ures_close), + Lib.method(:ures_close) ) resource_key = 'durationUnits/' @@ -147,7 +147,7 @@ def hms_duration_units_pattern(fields) Lib.check_error do |error| Lib.ures_getBykeyWithFallback(@unit_res_bundle, resource_key, nil, error) end, - Lib.method(:ures_close), + Lib.method(:ures_close) ) rescue MissingResourceError # This combination of h,m,s not present for this locale. @@ -253,9 +253,9 @@ def number_formatter(skeleton) FFI::AutoPointer.new( Lib.check_error do |error| Lib.unumf_openForSkeletonAndLocale(skeleton_uchar, skeleton_uchar.length_in_uchars, - @locale, error) + @locale, error) end, - Lib.method(:unumf_close), + Lib.method(:unumf_close) ) end end @@ -264,7 +264,7 @@ def format_number(value, skeleton) formatter = number_formatter(skeleton) result = FFI::AutoPointer.new( Lib.check_error { |error| Lib.unumf_openResult(error) }, - Lib.method(:unumf_closeResult), + Lib.method(:unumf_closeResult) ) value_str = value.to_s Lib.check_error do |error| diff --git a/lib/ffi-icu/lib.rb b/lib/ffi-icu/lib.rb index a3e14c1..48e569f 100644 --- a/lib/ffi-icu/lib.rb +++ b/lib/ffi-icu/lib.rb @@ -20,7 +20,7 @@ def self.search_paths [ '/usr/local/{lib64,lib}', '/opt/local/{lib64,lib}', - '/usr/{lib64,lib}', + '/usr/{lib64,lib}' ] + Dir['/usr/lib/*-linux-gnu'] # for Debian Multiarch http://wiki.debian.org/Multiarch end end @@ -56,9 +56,9 @@ def self.load_icu if !lib_names || lib_names.empty? raise(LoadError, - "Could not find ICU on #{ICU.platform.inspect}. " \ - 'Patches welcome, or you can add the containing directory yourself: ' \ - "#{self}.search_paths << '/path/to/lib'") + "Could not find ICU on #{ICU.platform.inspect}. " \ + 'Patches welcome, or you can add the containing directory yourself: ' \ + "#{self}.search_paths << '/path/to/lib'") end # And now try to load the library @@ -220,72 +220,72 @@ def self.attach_optional_function(*args) enum :layout_type, %i[ltr rtl ttb btt unknown] attach_function :uloc_canonicalize, "uloc_canonicalize#{suffix}", %i[string pointer int32_t pointer], - :int32_t + :int32_t attach_function :uloc_countAvailable, "uloc_countAvailable#{suffix}", [], :int32_t attach_function :uloc_getAvailable, "uloc_getAvailable#{suffix}", [:int32_t], :string attach_function :uloc_getBaseName, "uloc_getBaseName#{suffix}", %i[string pointer int32_t pointer], - :int32_t + :int32_t attach_function :uloc_getCountry, "uloc_getCountry#{suffix}", %i[string pointer int32_t pointer], - :int32_t + :int32_t attach_function :uloc_getDefault, "uloc_getDefault#{suffix}", [], :string attach_function :uloc_getISO3Country, "uloc_getISO3Country#{suffix}", [:string], :string attach_function :uloc_getISO3Language, "uloc_getISO3Language#{suffix}", [:string], :string attach_function :uloc_getISOCountries, "uloc_getISOCountries#{suffix}", [], :pointer attach_function :uloc_getISOLanguages, "uloc_getISOLanguages#{suffix}", [], :pointer attach_function :uloc_getKeywordValue, "uloc_getKeywordValue#{suffix}", - %i[string string pointer int32_t pointer], :int32_t + %i[string string pointer int32_t pointer], :int32_t attach_function :uloc_getLanguage, "uloc_getLanguage#{suffix}", %i[string pointer int32_t pointer], - :int32_t + :int32_t attach_function :uloc_getLCID, "uloc_getLCID#{suffix}", [:string], :uint32 attach_function :uloc_getName, "uloc_getName#{suffix}", %i[string pointer int32_t pointer], - :int32_t + :int32_t attach_function :uloc_getParent, "uloc_getParent#{suffix}", %i[string pointer int32_t pointer], - :int32_t + :int32_t attach_function :uloc_getScript, "uloc_getScript#{suffix}", %i[string pointer int32_t pointer], - :int32_t + :int32_t attach_function :uloc_getVariant, "uloc_getVariant#{suffix}", %i[string pointer int32_t pointer], - :int32_t + :int32_t attach_function :uloc_openKeywords, "uloc_openKeywords#{suffix}", %i[string pointer], :pointer attach_function :uloc_setDefault, "uloc_setDefault#{suffix}", %i[string pointer], :void attach_function :uloc_setKeywordValue, "uloc_setKeywordValue#{suffix}", - %i[string string pointer int32_t pointer], :int32_t + %i[string string pointer int32_t pointer], :int32_t attach_function :uloc_getDisplayCountry, "uloc_getDisplayCountry#{suffix}", - %i[string string pointer int32_t pointer], :int32_t + %i[string string pointer int32_t pointer], :int32_t attach_function :uloc_getDisplayKeyword, "uloc_getDisplayKeyword#{suffix}", - %i[string string pointer int32_t pointer], :int32_t + %i[string string pointer int32_t pointer], :int32_t attach_function :uloc_getDisplayKeywordValue, "uloc_getDisplayKeywordValue#{suffix}", - %i[string string string pointer int32_t pointer], :int32_t + %i[string string string pointer int32_t pointer], :int32_t attach_function :uloc_getDisplayLanguage, "uloc_getDisplayLanguage#{suffix}", - %i[string string pointer int32_t pointer], :int32_t + %i[string string pointer int32_t pointer], :int32_t attach_function :uloc_getDisplayName, "uloc_getDisplayName#{suffix}", - %i[string string pointer int32_t pointer], :int32_t + %i[string string pointer int32_t pointer], :int32_t attach_function :uloc_getDisplayScript, "uloc_getDisplayScript#{suffix}", - %i[string string pointer int32_t pointer], :int32_t + %i[string string pointer int32_t pointer], :int32_t attach_function :uloc_getDisplayVariant, "uloc_getDisplayVariant#{suffix}", - %i[string string pointer int32_t pointer], :int32_t + %i[string string pointer int32_t pointer], :int32_t if Gem::Version.new('3.8') <= Gem::Version.new(version) attach_function :uloc_getLocaleForLCID, "uloc_getLocaleForLCID#{suffix}", - %i[uint32 pointer int32_t pointer], :int32_t + %i[uint32 pointer int32_t pointer], :int32_t end if Gem::Version.new('4.0') <= Gem::Version.new(version) attach_function :uloc_addLikelySubtags, "uloc_addLikelySubtags#{suffix}", - %i[string pointer int32_t pointer], :int32_t + %i[string pointer int32_t pointer], :int32_t attach_function :uloc_minimizeSubtags, "uloc_minimizeSubtags#{suffix}", - %i[string pointer int32_t pointer], :int32_t + %i[string pointer int32_t pointer], :int32_t attach_function :uloc_getCharacterOrientation, "uloc_getCharacterOrientation#{suffix}", %i[string pointer], - :layout_type + :layout_type attach_function :uloc_getLineOrientation, "uloc_getLineOrientation#{suffix}", %i[string pointer], - :layout_type + :layout_type end if Gem::Version.new('4.2') <= Gem::Version.new(version) attach_function :uloc_forLanguageTag, "uloc_forLanguageTag#{suffix}", - %i[string pointer int32_t pointer pointer], :int32_t + %i[string pointer int32_t pointer pointer], :int32_t attach_function :uloc_toLanguageTag, "uloc_toLanguageTag#{suffix}", - %i[string pointer int32_t int8_t pointer], :int32_t + %i[string pointer int32_t int8_t pointer], :int32_t attach_function :ulocdata_getCLDRVersion, "ulocdata_getCLDRVersion#{suffix}", %i[version pointer], :void end @@ -298,24 +298,24 @@ def self.attach_optional_function(*args) attach_function :ucsdet_open, "ucsdet_open#{suffix}", [:pointer], :pointer attach_function :ucsdet_close, "ucsdet_close#{suffix}", [:pointer], :void attach_function :ucsdet_setText, "ucsdet_setText#{suffix}", - %i[pointer pointer int32_t pointer], :void + %i[pointer pointer int32_t pointer], :void attach_function :ucsdet_setDeclaredEncoding, "ucsdet_setDeclaredEncoding#{suffix}", - %i[pointer string int32_t pointer], :void + %i[pointer string int32_t pointer], :void attach_function :ucsdet_detect, "ucsdet_detect#{suffix}", - %i[pointer pointer], :pointer + %i[pointer pointer], :pointer attach_function :ucsdet_detectAll, "ucsdet_detectAll#{suffix}", - %i[pointer pointer pointer], :pointer + %i[pointer pointer pointer], :pointer attach_function :ucsdet_getName, "ucsdet_getName#{suffix}", - %i[pointer pointer], :string + %i[pointer pointer], :string attach_function :ucsdet_getConfidence, "ucsdet_getConfidence#{suffix}", - %i[pointer pointer], :int32_t + %i[pointer pointer], :int32_t attach_function :ucsdet_getLanguage, "ucsdet_getLanguage#{suffix}", - %i[pointer pointer], :string + %i[pointer pointer], :string attach_function :ucsdet_getAllDetectableCharsets, "ucsdet_getAllDetectableCharsets#{suffix}", - %i[pointer pointer], :pointer + %i[pointer pointer], :pointer attach_function :ucsdet_isInputFilterEnabled, "ucsdet_isInputFilterEnabled#{suffix}", [:pointer], :bool attach_function :ucsdet_enableInputFilter, "ucsdet_enableInputFilter#{suffix}", - %i[pointer bool], :bool + %i[pointer bool], :bool # Collation # @@ -325,21 +325,21 @@ def self.attach_optional_function(*args) attach_function :ucol_open, "ucol_open#{suffix}", %i[string pointer], :pointer attach_function :ucol_close, "ucol_close#{suffix}", [:pointer], :void attach_function :ucol_strcoll, "ucol_strcoll#{suffix}", - %i[pointer pointer int32_t pointer int32_t], :int + %i[pointer pointer int32_t pointer int32_t], :int attach_function :ucol_getKeywords, "ucol_getKeywords#{suffix}", [:pointer], :pointer attach_function :ucol_getKeywordValues, "ucol_getKeywordValues#{suffix}", %i[string pointer], :pointer attach_function :ucol_getAvailable, "ucol_getAvailable#{suffix}", [:int32_t], :string attach_function :ucol_countAvailable, "ucol_countAvailable#{suffix}", [], :int32_t attach_function :ucol_getLocale, "ucol_getLocale#{suffix}", %i[pointer int pointer], :string attach_function :ucol_greater, "ucol_greater#{suffix}", - %i[pointer pointer int32_t pointer int32_t], :bool + %i[pointer pointer int32_t pointer int32_t], :bool attach_function :ucol_greaterOrEqual, "ucol_greaterOrEqual#{suffix}", - %i[pointer pointer int32_t pointer int32_t], :bool + %i[pointer pointer int32_t pointer int32_t], :bool attach_function :ucol_equal, "ucol_equal#{suffix}", - %i[pointer pointer int32_t pointer int32_t], :bool + %i[pointer pointer int32_t pointer int32_t], :bool attach_function :ucol_getRules, "ucol_getRules#{suffix}", %i[pointer pointer], :pointer attach_function :ucol_getSortKey, "ucol_getSortKey#{suffix}", - %i[pointer pointer int pointer int], :int + %i[pointer pointer int pointer int], :int attach_function :ucol_getAttribute, "ucol_getAttribute#{suffix}", %i[pointer int pointer], :int attach_function :ucol_setAttribute, "ucol_setAttribute#{suffix}", %i[pointer int int pointer], :void @@ -350,33 +350,33 @@ def self.attach_optional_function(*args) class UParseError < FFI::Struct layout :line, :int32_t, - :offset, :int32_t, - :pre_context, :pointer, - :post_context, :pointer + :offset, :int32_t, + :pre_context, :pointer, + :post_context, :pointer def to_s format('#<%s:%x line: %d offset: %d', - class: self.class, hash: hash * 2, line: self[:line], offset: self[:offset]) + class: self.class, hash: hash * 2, line: self[:line], offset: self[:offset]) end end class UTransPosition < FFI::Struct layout :context_start, :int32_t, - :context_limit, :int32_t, - :start, :int32_t, - :end, :int32_t + :context_limit, :int32_t, + :start, :int32_t, + :end, :int32_t end enum :trans_direction, %i[forward reverse] attach_function :utrans_openIDs, "utrans_openIDs#{suffix}", [:pointer], :pointer attach_function :utrans_openU, "utrans_openU#{suffix}", - %i[pointer int32_t trans_direction pointer int32_t pointer pointer], :pointer + %i[pointer int32_t trans_direction pointer int32_t pointer pointer], :pointer attach_function :utrans_open, "utrans_open#{suffix}", - %i[string trans_direction pointer int32_t pointer pointer], :pointer + %i[string trans_direction pointer int32_t pointer pointer], :pointer attach_function :utrans_close, "utrans_close#{suffix}", [:pointer], :void attach_function :utrans_transUChars, "utrans_transUChars#{suffix}", - %i[pointer pointer pointer int32_t int32_t pointer pointer], :void + %i[pointer pointer pointer int32_t int32_t pointer pointer], :void # Normalization # @@ -392,18 +392,18 @@ class UTransPosition < FFI::Struct :fcd, 6] attach_function :unorm_normalize, "unorm_normalize#{suffix}", - %i[pointer int32_t normalization_mode int32_t pointer int32_t pointer], :int32_t + %i[pointer int32_t normalization_mode int32_t pointer int32_t pointer], :int32_t # http://icu-project.org/apiref/icu4c/unorm2_8h.html if Gem::Version.new('4.4') <= Gem::Version.new(version) enum :normalization2_mode, %i[compose decompose fcd compose_contiguous] attach_function :unorm2_getInstance, "unorm2_getInstance#{suffix}", - %i[pointer pointer normalization2_mode pointer], :pointer + %i[pointer pointer normalization2_mode pointer], :pointer attach_function :unorm2_normalize, "unorm2_normalize#{suffix}", - %i[pointer pointer int32_t pointer int32_t pointer], :int32_t + %i[pointer pointer int32_t pointer int32_t pointer], :int32_t attach_function :unorm2_isNormalized, "unorm2_isNormalized#{suffix}", %i[pointer pointer int32_t pointer], - :bool + :bool end # @@ -428,10 +428,10 @@ class UTransPosition < FFI::Struct attach_function :ubrk_getAvailable, "ubrk_getAvailable#{suffix}", [:int32_t], :string attach_function :ubrk_open, "ubrk_open#{suffix}", - %i[iterator_type string pointer int32_t pointer], :pointer + %i[iterator_type string pointer int32_t pointer], :pointer attach_function :ubrk_close, "ubrk_close#{suffix}", [:pointer], :void attach_function :ubrk_setText, "ubrk_setText#{suffix}", - %i[pointer pointer int32_t pointer], :void + %i[pointer pointer int32_t pointer], :void attach_function :ubrk_current, "ubrk_current#{suffix}", [:pointer], :int32_t attach_function :ubrk_next, "ubrk_next#{suffix}", [:pointer], :int32_t attach_function :ubrk_previous, "ubrk_previous#{suffix}", [:pointer], :int32_t @@ -467,27 +467,27 @@ class UTransPosition < FFI::Struct significant_digits_used min_significant_digits max_significant_digits lenient_parse ] attach_function :unum_open, "unum_open#{suffix}", - %i[number_format_style pointer int32_t string pointer pointer], :pointer + %i[number_format_style pointer int32_t string pointer pointer], :pointer attach_function :unum_close, "unum_close#{suffix}", [:pointer], :void attach_function :unum_format_int32, "unum_format#{suffix}", - %i[pointer int32_t pointer int32_t pointer pointer], :int32_t + %i[pointer int32_t pointer int32_t pointer pointer], :int32_t attach_function :unum_format_int64, "unum_formatInt64#{suffix}", - %i[pointer int64_t pointer int32_t pointer pointer], :int32_t + %i[pointer int64_t pointer int32_t pointer pointer], :int32_t attach_function :unum_format_double, "unum_formatDouble#{suffix}", - %i[pointer double pointer int32_t pointer pointer], :int32_t + %i[pointer double pointer int32_t pointer pointer], :int32_t attach_optional_function :unum_format_decimal, "unum_formatDecimal#{suffix}", - %i[pointer string int32_t pointer int32_t pointer pointer], :int32_t + %i[pointer string int32_t pointer int32_t pointer pointer], :int32_t attach_function :unum_format_currency, "unum_formatDoubleCurrency#{suffix}", - %i[pointer double pointer pointer int32_t pointer pointer], :int32_t + %i[pointer double pointer pointer int32_t pointer pointer], :int32_t attach_function :unum_set_attribute, "unum_setAttribute#{suffix}", %i[pointer number_format_attribute int32_t], - :void + :void # UResourceBundle attach_function :ures_open, "ures_open#{suffix}", %i[string string pointer], :pointer attach_function :ures_close, "ures_close#{suffix}", [:pointer], :void # This function is marked "internal" but it's fully exported by the library ABI, so we can use it anyway. attach_function :ures_getBykeyWithFallback, "ures_getByKeyWithFallback#{suffix}", - %i[pointer string pointer pointer], :pointer + %i[pointer string pointer pointer], :pointer attach_function :ures_getString, "ures_getString#{suffix}", %i[pointer pointer pointer], :pointer def self.resource_bundle_name(type) @@ -497,14 +497,14 @@ def self.resource_bundle_name(type) # UNumberFormatter attach_optional_function :unumf_openForSkeletonAndLocale, "unumf_openForSkeletonAndLocale#{suffix}", - %i[pointer int32_t string pointer], :pointer + %i[pointer int32_t string pointer], :pointer attach_optional_function :unumf_close, "unumf_close#{suffix}", [:pointer], :void attach_optional_function :unumf_openResult, "unumf_openResult#{suffix}", [:pointer], :pointer attach_optional_function :unumf_closeResult, "unumf_closeResult#{suffix}", [:pointer], :void attach_optional_function :unumf_formatDecimal, "unumf_formatDecimal#{suffix}", - %i[pointer string int32_t pointer pointer], :void + %i[pointer string int32_t pointer pointer], :void attach_optional_function :unumf_resultToString, "unumf_resultToString#{suffix}", - %i[pointer pointer int32_t pointer], :int32_t + %i[pointer pointer int32_t pointer], :int32_t # UListFormatter enum :ulistfmt_type, [ @@ -518,10 +518,10 @@ def self.resource_bundle_name(type) :narrow, 2 ] attach_optional_function :ulistfmt_openForType, "ulistfmt_openForType#{suffix}", - %i[string ulistfmt_type ulistfmt_width pointer], :pointer + %i[string ulistfmt_type ulistfmt_width pointer], :pointer attach_optional_function :ulistfmt_close, "ulistfmt_close#{suffix}", [:pointer], :void attach_optional_function :ulistfmt_format, "ulistfmt_format#{suffix}", - %i[pointer pointer pointer int32_t pointer int32_t pointer], :int32_t + %i[pointer pointer pointer int32_t pointer int32_t pointer], :int32_t # date enum :date_format_style, [ @@ -537,32 +537,32 @@ def self.resource_bundle_name(type) :valid_locale, 1 ] attach_function :udat_open, "udat_open#{suffix}", - %i[date_format_style date_format_style string pointer int32_t pointer int32_t pointer], :pointer + %i[date_format_style date_format_style string pointer int32_t pointer int32_t pointer], :pointer attach_function :udat_close, "unum_close#{suffix}", [:pointer], :void attach_function :udat_format, "udat_format#{suffix}", %i[pointer double pointer int32_t pointer pointer], - :int32_t + :int32_t attach_function :udat_parse, "udat_parse#{suffix}", %i[pointer pointer int32_t pointer pointer], :double attach_function :udat_toPattern, "udat_toPattern#{suffix}", - %i[pointer bool pointer int32_t pointer], :int32_t + %i[pointer bool pointer int32_t pointer], :int32_t attach_function :udat_applyPattern, "udat_applyPattern#{suffix}", %i[pointer bool pointer int32_t], - :void + :void # skeleton pattern attach_function :udatpg_open, "udatpg_open#{suffix}", %i[string pointer], :pointer attach_function :udatpg_close, "udatpg_close#{suffix}", [:pointer], :void attach_function :udatpg_getBestPattern, "udatpg_getBestPattern#{suffix}", - %i[pointer pointer int32_t pointer int32_t pointer], :int32_t + %i[pointer pointer int32_t pointer int32_t pointer], :int32_t attach_function :udatpg_getSkeleton, "udatpg_getSkeleton#{suffix}", - %i[pointer pointer int32_t pointer int32_t pointer], :int32_t + %i[pointer pointer int32_t pointer int32_t pointer], :int32_t # tz attach_function :ucal_setDefaultTimeZone, "ucal_setDefaultTimeZone#{suffix}", %i[pointer pointer], :int32_t attach_function :ucal_getDefaultTimeZone, "ucal_getDefaultTimeZone#{suffix}", %i[pointer int32_t pointer], - :int32_t + :int32_t # ULocaleDisplayNames attach_function :uldn_openForContext, "uldn_openForContext#{suffix}", %i[string pointer int32_t pointer], - :pointer + :pointer attach_function :uldn_localeDisplayName, "uldn_localeDisplayName#{suffix}", - %i[pointer string pointer int32_t pointer], :int32_t + %i[pointer string pointer int32_t pointer], :int32_t attach_function :uldn_close, "uldn_close#{suffix}", [:pointer], :void end end diff --git a/lib/ffi-icu/locale.rb b/lib/ffi-icu/locale.rb index ccc8d4b..e1301ac 100644 --- a/lib/ffi-icu/locale.rb +++ b/lib/ffi-icu/locale.rb @@ -44,7 +44,7 @@ def iso_languages DISPLAY_CONTEXT = { length_full: 512, # UDISPCTX_LENGTH_FULL = (UDISPCTX_TYPE_DISPLAY_LENGTH<<8) + 0 - length_short: 513, # UDISPCTX_LENGTH_SHORT = (UDISPCTX_TYPE_DISPLAY_LENGTH<<8) + 1 + length_short: 513 # UDISPCTX_LENGTH_SHORT = (UDISPCTX_TYPE_DISPLAY_LENGTH<<8) + 1 }.freeze def initialize(id) @@ -183,13 +183,11 @@ def script end end - # rubocop:disable Style/OptionalBooleanParameter - def to_language_tag(strict = false) + def to_language_tag(strict = false) # rubocop:disable Style/OptionalBooleanParameter Lib::Util.read_string_buffer(64) do |buffer, status| Lib.uloc_toLanguageTag(@id, buffer, buffer.size, strict ? 1 : 0, status) end end - # rubocop:enable Style/OptionalBooleanParameter alias to_s id diff --git a/lib/ffi-icu/normalizer.rb b/lib/ffi-icu/normalizer.rb index 2d6e509..bca85d4 100644 --- a/lib/ffi-icu/normalizer.rb +++ b/lib/ffi-icu/normalizer.rb @@ -32,8 +32,7 @@ def normalize(input) out_ptr.string end - # rubocop:disable Naming/PredicateName - def is_normailzed?(input) + def is_normailzed?(input) # rubocop:disable Naming/PredicateName input_length = input.jlength in_ptr = UCharPointer.from_string(input) @@ -43,6 +42,5 @@ def is_normailzed?(input) result end - # rubocop:enable Naming/PredicateName end end diff --git a/lib/ffi-icu/number_formatting.rb b/lib/ffi-icu/number_formatting.rb index c9b8d07..69a35cb 100644 --- a/lib/ffi-icu/number_formatting.rb +++ b/lib/ffi-icu/number_formatting.rb @@ -17,11 +17,9 @@ def self.clear_default_options @default_options.clear end - # rubocop:disable Naming/AccessorMethodName - def self.set_default_options(options) + def self.set_default_options(options) # rubocop:disable Naming/AccessorMethodName @default_options.merge!(options) end - # rubocop:enable Naming/AccessorMethodName def self.format_number(locale, number, options = {}) create(locale, :decimal, options).format(number) @@ -40,12 +38,10 @@ def self.spell(locale, number, options = {}) end class BaseFormatter - # rubocop:disable Naming/AccessorMethodName - def set_attributes(options) + def set_attributes(options) # rubocop:disable Naming/AccessorMethodName options.each { |key, value| Lib.unum_set_attribute(@f, key, value) } self end - # rubocop:enable Naming/AccessorMethodName private @@ -87,13 +83,13 @@ def format(number) end string_version = number.to_s needed_length = Lib.unum_format_decimal(@f, string_version, string_version.bytesize, out_ptr, - needed_length, nil, error) + needed_length, nil, error) end when BigDecimal string_version = number.to_s('F') needed_length = if Lib.respond_to?(:unum_format_decimal) Lib.unum_format_decimal(@f, string_version, string_version.bytesize, out_ptr, - needed_length, nil, error) + needed_length, nil, error) else Lib.unum_format_double(@f, number.to_f, out_ptr, needed_length, nil, error) end @@ -139,7 +135,7 @@ def format(number, currency) begin Lib.check_error do |error| needed_length = Lib.unum_format_currency(@f, number, UCharPointer.from_string(currency, 4), out_ptr, - needed_length, nil, error) + needed_length, nil, error) end out_ptr.string rescue BufferOverflowError diff --git a/lib/ffi-icu/time_formatting.rb b/lib/ffi-icu/time_formatting.rb index 39b6142..031cc43 100644 --- a/lib/ffi-icu/time_formatting.rb +++ b/lib/ffi-icu/time_formatting.rb @@ -46,7 +46,7 @@ module TimeFormatting # the localized exemplar city name for the special zone Etc/Unknown is used as the fallback # (for example, "Unknown City"), such as Los Angeles # see: http://unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns - city_location: 'VVV', + city_location: 'VVV' }.freeze HOUR_CYCLE_SYMS = { @@ -54,7 +54,7 @@ module TimeFormatting 'h12' => 'h', 'h23' => 'H', 'h24' => 'k', - :locale => 'j', + :locale => 'j' }.freeze @default_options = {} @@ -66,23 +66,19 @@ def self.clear_default_options @default_options.clear end - # rubocop:disable Naming/AccessorMethodName - def self.set_default_options(options) + def self.set_default_options(options) # rubocop:disable Naming/AccessorMethodName @default_options.merge!(options) end - # rubocop:enable Naming/AccessorMethodName def self.format(datetime, options = {}) create(@default_options.merge(options)).format(datetime) end class BaseFormatter - # rubocop:disable Naming/AccessorMethodName - def set_attributes(options) + def set_attributes(options) # rubocop:disable Naming/AccessorMethodName options.each { |key, value| Lib.unum_set_attribute(@f, key, value) } self end - # rubocop:enable Naming/AccessorMethodName private @@ -200,8 +196,7 @@ def update_tz_format(format, tz_style) pre + tz + suff end - # rubocop:disable Style/OptionalBooleanParameter - def date_format(localized = true) + def date_format(localized = true) # rubocop:disable Style/OptionalBooleanParameter needed_length = 0 out_ptr = UCharPointer.new(needed_length) @@ -221,7 +216,6 @@ def date_format(localized = true) retry end end - # rubocop:enable Style/OptionalBooleanParameter def set_date_format(localized, pattern_str) set_date_format_impl(localized, pattern_str) @@ -246,7 +240,7 @@ def skeleton_format(skeleton_pattern_str, locale) begin Lib.check_error do |error| needed_length = Lib.udatpg_getBestPattern(generator, skeleton_pattern_ptr, skeleton_pattern_len, - pattern_ptr, needed_length, error) + pattern_ptr, needed_length, error) end [needed_length, pattern_ptr] @@ -316,7 +310,7 @@ def replace_hour_symbol! def datetime_pattern_generator @datetime_pattern_generator ||= FFI::AutoPointer.new( Lib.check_error { |error| Lib.udatpg_open(@locale, error) }, - Lib.method(:udatpg_close), + Lib.method(:udatpg_close) ) end diff --git a/lib/ffi-icu/transliteration.rb b/lib/ffi-icu/transliteration.rb index a7ff034..b125743 100644 --- a/lib/ffi-icu/transliteration.rb +++ b/lib/ffi-icu/transliteration.rb @@ -32,7 +32,7 @@ def initialize(id, rules = nil, direction = :forward) begin Lib.check_error do |status| ptr = Lib.utrans_openU(UCharPointer.from_string(id), id.jlength, direction, rules, rules_length, - @parse_error, status) + @parse_error, status) @tr = FFI::AutoPointer.new(ptr, Lib.method(:utrans_close)) end rescue ICU::Error => e diff --git a/spec/break_iterator_spec.rb b/spec/break_iterator_spec.rb index 0d5cb7d..7396ac8 100644 --- a/spec/break_iterator_spec.rb +++ b/spec/break_iterator_spec.rb @@ -12,9 +12,10 @@ module ICU iterator.text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, ' \ 'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.' expect(iterator.to_a).to(eq( - [0, 5, 6, 11, 12, 17, 18, 21, 22, 26, 27, 28, 39, 40, 51, 52, 56, 57, 58, 61, 62, 64, 65, 72, 73, 79, 80, 90, - 91, 93, 94, 100, 101, 103, 104, 110, 111, 116, 117, 123, 124], - )) + [0, 5, 6, 11, 12, 17, 18, 21, 22, 26, 27, 28, 39, 40, 51, 52, + 56, 57, 58, 61, 62, 64, 65, 72, 73, 79, 80, 90, 91, 93, 94, 100, + 101, 103, 104, 110, 111, 116, 117, 123, 124] + )) end it 'returns each substring' do @@ -29,8 +30,9 @@ module ICU iterator.text = 'รู้อะไรไม่สู้รู้วิชา รู้รักษาตัวรอดเป็นยอดดี' expect(iterator.substrings).to(eq( - ['รู้', 'อะไร', 'ไม่สู้', 'รู้', 'วิชา', ' ', 'รู้', 'รักษา', 'ตัว', 'รอด', 'เป็น', 'ยอดดี'], - )) + ['รู้', 'อะไร', 'ไม่สู้', 'รู้', 'วิชา', ' ', 'รู้', 'รักษา', 'ตัว', 'รอด', + 'เป็น', 'ยอดดี'] + )) end it 'finds all word boundaries in a non-ASCII string' do diff --git a/spec/duration_formatting_spec.rb b/spec/duration_formatting_spec.rb index 2da349a..94262c1 100644 --- a/spec/duration_formatting_spec.rb +++ b/spec/duration_formatting_spec.rb @@ -92,7 +92,7 @@ module DurationFormatting seconds: 7, milliseconds: 8, microseconds: 9, - nanoseconds: 10, + nanoseconds: 10 } result = DurationFormatting.format(duration, locale: 'en-AU', style: :short) expect(result).to(match(/1.yr.*2.*mths.*3.*wks.*4.*days.*5.*hrs.*6.*mins.*7.*secs.*8.*ms.*9.*μs.*10.*ns/)) diff --git a/spec/locale_spec.rb b/spec/locale_spec.rb index ec7712d..76014f5 100644 --- a/spec/locale_spec.rb +++ b/spec/locale_spec.rb @@ -81,7 +81,7 @@ module ICU expect(described_class.new('zh_Hans_CH_PINYIN').to_language_tag).to(eq('zh-Hans-CH-u-co-pinyin')) else expect(described_class.new('zh_Hans_CH@collation=pinyin').to_language_tag).to( - eq('zh-Hans-CH-u-co-pinyin'), + eq('zh-Hans-CH-u-co-pinyin') ) end else @@ -126,9 +126,11 @@ module ICU it 'returns the name using display context' do expect(described_class.new('en_HK').display_name_with_context('en_US', - [:length_full])).to(eq('English (Hong Kong SAR China)')) + [:length_full])).to( + eq('English (Hong Kong SAR China)') + ) expect(described_class.new('en_HK').display_name_with_context('en_US', - [:length_short])).to(eq('English (Hong Kong)')) + [:length_short])).to(eq('English (Hong Kong)')) end it 'returns the script' do @@ -230,9 +232,9 @@ module ICU it 'can be added' do expect(described_class.new('de_DE').with_keyword('currency', - 'EUR')).to(eq(described_class.new('de_DE@currency=EUR'))) + 'EUR')).to(eq(described_class.new('de_DE@currency=EUR'))) expect(described_class.new('de_DE').with_keyword(:currency, - :EUR)).to(eq(described_class.new('de_DE@currency=EUR'))) + :EUR)).to(eq(described_class.new('de_DE@currency=EUR'))) end it 'can be added using hash' do diff --git a/spec/number_formatting_spec.rb b/spec/number_formatting_spec.rb index 3492213..06d3bd9 100644 --- a/spec/number_formatting_spec.rb +++ b/spec/number_formatting_spec.rb @@ -36,7 +36,9 @@ module NumberFormatting it 'spells numbers' do expect(NumberFormatting.spell('en_US', 1_000)).to(eq('one thousand')) expect(NumberFormatting.spell('de-DE', - 123.456)).to(eq("ein\u{AD}hundert\u{AD}drei\u{AD}und\u{AD}zwanzig Komma vier fünf sechs")) + 123.456)).to( + eq("ein\u{AD}hundert\u{AD}drei\u{AD}und\u{AD}zwanzig Komma vier fünf sechs") + ) end it 'is able to re-use number formatter objects' do diff --git a/spec/time_spec.rb b/spec/time_spec.rb index 411a837..c0d939d 100644 --- a/spec/time_spec.rb +++ b/spec/time_spec.rb @@ -12,7 +12,7 @@ module ICU t8 = Time.at(1_206_761_904) # in TZ=Europe/Prague Time.mktime(2008, 03, 29, 04, 38, 24) f1 = described_class.create(locale: 'cs_CZ', zone: 'Europe/Prague', date: :long, time: :long, - tz_style: :localized_long) + tz_style: :localized_long) it 'check date_format for lang=cs_CZ' do expect(f1.date_format(true)).to(eq('d. MMMM y H:mm:ss ZZZZ')) expect(f1.date_format(false)).to(eq('d. MMMM y H:mm:ss ZZZZ')) @@ -32,7 +32,7 @@ module ICU end f2 = described_class.create(locale: 'en_US', zone: 'Europe/Moscow', date: :short, time: :long, - tz_style: :generic_location) + tz_style: :generic_location) cldr_version = Lib.cldr_version.to_s en_tz = 'Moscow Time' en_sep = ',' @@ -101,7 +101,7 @@ module ICU it 'works with hour_cycle: h11' do t = Time.new(2021, 0o4, 0o1, 12, 0o5, 0, '+00:00') str = described_class.format(t, time: :short, date: :none, locale: locale_name, zone: 'UTC', - hour_cycle: 'h11') + hour_cycle: 'h11') expect(str).to(match(/0:05/i)) expect(str).to(match(/(pm|下午)/i)) end @@ -109,7 +109,7 @@ module ICU it 'works with hour_cycle: h12' do t = Time.new(2021, 0o4, 0o1, 12, 0o5, 0, '+00:00') str = described_class.format(t, time: :short, date: :none, locale: locale_name, zone: 'UTC', - hour_cycle: 'h12') + hour_cycle: 'h12') expect(str).to(match(/12:05/i)) expect(str).to(match(/(pm|下午)/i)) end @@ -117,7 +117,7 @@ module ICU it 'works with hour_cycle: h23' do t = Time.new(2021, 0o4, 0o1, 0o0, 0o5, 0, '+00:00') str = described_class.format(t, time: :short, date: :none, locale: locale_name, zone: 'UTC', - hour_cycle: 'h23') + hour_cycle: 'h23') expect(str).to(match(/0:05/i)) expect(str).not_to(match(/(am|pm)/i)) end @@ -125,7 +125,7 @@ module ICU it 'works with hour_cycle: h24' do t = Time.new(2021, 0o4, 0o1, 0o0, 0o5, 0, '+00:00') str = described_class.format(t, time: :short, date: :none, locale: locale_name, zone: 'UTC', - hour_cycle: 'h24') + hour_cycle: 'h24') expect(str).to(match(/24:05/i)) expect(str).not_to(match(/(am|pm)/i)) end @@ -133,7 +133,7 @@ module ICU it 'does not include am/pm if time is not requested' do t = Time.new(2021, 0o4, 0o1, 0o0, 0o5, 0, '+00:00') str = described_class.format(t, time: :none, date: :short, locale: locale_name, zone: 'UTC', - hour_cycle: 'h12') + hour_cycle: 'h12') expect(str).not_to(match(/(am|pm|下午|上午)/i)) end @@ -146,7 +146,7 @@ module ICU t = Time.new(2021, 0o4, 0o1, 12, 0o5, 0, '+00:00') locale = Locale.new(locale_name).with_keyword('hours', 'h11').to_s str = described_class.format(t, time: :short, date: :none, locale: locale, zone: 'UTC', - hour_cycle: :locale) + hour_cycle: :locale) expect(str).to(match(/0:05/i)) expect(str).to(match(/(pm|下午)/i)) end @@ -155,7 +155,7 @@ module ICU t = Time.new(2021, 0o4, 0o1, 12, 0o5, 0, '+00:00') locale = Locale.new(locale_name).with_keyword('hours', 'h12').to_s str = described_class.format(t, time: :short, date: :none, locale: locale, zone: 'UTC', - hour_cycle: :locale) + hour_cycle: :locale) expect(str).to(match(/12:05/i)) expect(str).to(match(/(pm|下午)/i)) end @@ -164,7 +164,7 @@ module ICU t = Time.new(2021, 0o4, 0o1, 0o0, 0o5, 0, '+00:00') locale = Locale.new(locale_name).with_keyword('hours', 'h23').to_s str = described_class.format(t, time: :short, date: :none, locale: locale, zone: 'UTC', - hour_cycle: :locale) + hour_cycle: :locale) expect(str).to(match(/0:05/i)) expect(str).not_to(match(/(am|pm)/i)) end @@ -173,7 +173,7 @@ module ICU t = Time.new(2021, 0o4, 0o1, 0o0, 0o5, 0, '+00:00') locale = Locale.new(locale_name).with_keyword('hours', 'h24').to_s str = described_class.format(t, time: :short, date: :none, locale: locale, zone: 'UTC', - hour_cycle: :locale) + hour_cycle: :locale) expect(str).to(match(/24:05/i)) expect(str).not_to(match(/(am|pm)/i)) end @@ -184,7 +184,7 @@ module ICU it 'for lang=fi hour_cycle=h12' do t = Time.new(2021, 0o4, 0o1, 13, 0o5, 0, '+00:00') str = described_class.format(t, locale: 'fi', zone: 'America/Los_Angeles', date: :long, time: :short, - hour_cycle: 'h12') + hour_cycle: 'h12') expect(str).to(match(/\sklo\s/)) end diff --git a/spec/transliteration_spec.rb b/spec/transliteration_spec.rb index 7cb3986..d868718 100644 --- a/spec/transliteration_spec.rb +++ b/spec/transliteration_spec.rb @@ -9,7 +9,7 @@ def transliterator_for(*args) ['Lower', 'ABC', 'abc'], ['Han-Latin', '雙屬性集合之空間分群演算法-應用於地理資料', 'shuāng shǔ xìng jí hé zhī kōng jiān fēn qún yǎn suàn fǎ-yīng yòng yú de lǐ zī liào'], - ['Devanagari-Latin', 'दौलत', 'daulata'], + ['Devanagari-Latin', 'दौलत', 'daulata'] ].each do |id, input, output| it "transliterates #{id}" do tl = transliterator_for(id)