Class: FFI::Locale::LocaleConv

Inherits:
Object
  • Object
show all
Defined in:
lib/ffi-locale.rb

Overview

Structure returned by #localeconv containing information about numeric and monetary notation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lcs) ⇒ FFI::Locale::LocaleConv

Used by FFI::Locale.localeconv. Should not be called by application code directly.

Parameters:

  • lcs (FFI::Pointer)

    pointer to lconv struct returned by (private) function FFI::Locale#_localeconv.



226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/ffi-locale.rb', line 226

def initialize(lcs)
  lcs.layout.members.each do |key|
    value = lcs[key]
    case key
    when :grouping, :mon_grouping
      value = value.each_byte.to_a
    when :p_cs_precedes, :p_sep_precedes, :n_cs_precedes, :p_sep_by_space, :n_cs_precedes, :n_sep_by_space,
      :int_p_cs_precedes, :int_p_sep_by_space, :int_n_cs_precedes, :int_n_sep_by_space
      value = value == 1 ? true : false
    end
    case value
    when String
      if RUBY_VERSION >= '1.9.0'
        value = value.force_encoding(Encoding.default_external.to_s)
      end
      # For 1.8.x you need to handle this yourself.
    end
    instance_variable_set("@#{key}", value)
  end
end

Instance Attribute Details

#currency_symbolString (readonly)

Returns Local currency symbol, e.g. "£", "$".

Returns:

  • (String)

    Local currency symbol, e.g. "£", "$".



141
142
143
# File 'lib/ffi-locale.rb', line 141

def currency_symbol
  @currency_symbol
end

#decimal_pointString (readonly)

Returns Decimal point character.

Returns:

  • (String)

    Decimal point character.



120
121
122
# File 'lib/ffi-locale.rb', line 120

def decimal_point
  @decimal_point
end

#frac_digitsInteger (readonly)

Returns Local fractional digits.

Returns:

  • (Integer)

    Local fractional digits.



163
164
165
# File 'lib/ffi-locale.rb', line 163

def frac_digits
  @frac_digits
end

#groupingArray (readonly)

Each element is the number of digits in each group; elements with higher indices are farther left. An element with value CHAR_MAX means that no further grouping is done. An element with value 0 means that the previous element is used for all groups farther left.

Returns:

  • (Array)

    Grouping.



131
132
133
# File 'lib/ffi-locale.rb', line 131

def grouping
  @grouping
end

#int_curr_symbolString (readonly)

First three chars are a currency symbol from ISO 4217. Fourth char is the separator. For example, "GBP ", "USD ".

Returns:

  • (String)

    Int’l currency symbol.



138
139
140
# File 'lib/ffi-locale.rb', line 138

def int_curr_symbol
  @int_curr_symbol
end

#int_frac_digitsInteger (readonly)

Returns Int’l fractional digits.

Returns:

  • (Integer)

    Int’l fractional digits.



160
161
162
# File 'lib/ffi-locale.rb', line 160

def int_frac_digits
  @int_frac_digits
end

#int_n_cs_precedesBoolean (readonly)

Returns true if #int_curr_symbol precedes a negative value, false if succeeds.

Returns:

  • (Boolean)

    true if #int_curr_symbol precedes a negative value, false if succeeds.



200
201
202
# File 'lib/ffi-locale.rb', line 200

def int_n_cs_precedes
  @int_n_cs_precedes
end

#int_n_sep_by_spaceBoolean (readonly)

Returns true iff a space separates #int_curr_symbol from a negative value.

Returns:

  • (Boolean)

    true iff a space separates #int_curr_symbol from a negative value.



203
204
205
# File 'lib/ffi-locale.rb', line 203

def int_n_sep_by_space
  @int_n_sep_by_space
end

#int_n_sign_posnInteger (readonly)

Returns Negative sign position.

Returns:

  • (Integer)

    Negative sign position.

See Also:



217
218
219
# File 'lib/ffi-locale.rb', line 217

def int_n_sign_posn
  @int_n_sign_posn
end

#int_p_cs_precedesBoolean (readonly)

Returns true if #int_curr_symbol precedes a positive value, false if succeeds.

Returns:

  • (Boolean)

    true if #int_curr_symbol precedes a positive value, false if succeeds.



194
195
196
# File 'lib/ffi-locale.rb', line 194

def int_p_cs_precedes
  @int_p_cs_precedes
end

#int_p_sep_by_spaceBoolean (readonly)

Returns true iff a space separates #int_curr_symbol from a positive value.

Returns:

  • (Boolean)

    true iff a space separates #int_curr_symbol from a positive value.



197
198
199
# File 'lib/ffi-locale.rb', line 197

def int_p_sep_by_space
  @int_p_sep_by_space
end

#int_p_sign_posnInteger (readonly)

0

Parentheses surround the quantity and int_curr_symbol.

1

The sign string precedes the quantity and int_curr_symbol.

2

The sign string follows the quantity and int_curr_symbol.

3

The sign string immediately precedes the int_curr_symbol.

4

The sign string immediately follows the int_curr_symbol.

Returns:

  • (Integer)

    Positive sign position.



213
214
215
# File 'lib/ffi-locale.rb', line 213

def int_p_sign_posn
  @int_p_sign_posn
end

#mon_decimal_pointString (readonly)

Returns Decimal point character, e.g. ".", ",".

Returns:

  • (String)

    Decimal point character, e.g. ".", ",".



144
145
146
# File 'lib/ffi-locale.rb', line 144

def mon_decimal_point
  @mon_decimal_point
end

#mon_groupingArray (readonly)

Returns Like #grouping element.

Returns:

See Also:



151
152
153
# File 'lib/ffi-locale.rb', line 151

def mon_grouping
  @mon_grouping
end

#mon_thousands_sepString (readonly)

Returns Thousands separator.

Returns:

  • (String)

    Thousands separator.



147
148
149
# File 'lib/ffi-locale.rb', line 147

def mon_thousands_sep
  @mon_thousands_sep
end

#n_cs_precedesBoolean (readonly)

Returns true if #currency_symbol precedes a negative value, false if succeeds.

Returns:

  • (Boolean)

    true if #currency_symbol precedes a negative value, false if succeeds.



172
173
174
# File 'lib/ffi-locale.rb', line 172

def n_cs_precedes
  @n_cs_precedes
end

#n_sep_by_spaceBoolean (readonly)

Returns true iff a space separates #currency_symbol from a negative value.

Returns:

  • (Boolean)

    true iff a space separates #currency_symbol from a negative value.



175
176
177
# File 'lib/ffi-locale.rb', line 175

def n_sep_by_space
  @n_sep_by_space
end

#n_sign_posnInteger (readonly)

Returns Negative sign position.

Returns:

  • (Integer)

    Negative sign position.

See Also:



189
190
191
# File 'lib/ffi-locale.rb', line 189

def n_sign_posn
  @n_sign_posn
end

#negative_signString (readonly)

Returns Sign for negative values.

Returns:

  • (String)

    Sign for negative values.



157
158
159
# File 'lib/ffi-locale.rb', line 157

def negative_sign
  @negative_sign
end

#p_cs_precedesBoolean (readonly)

Returns true if #currency_symbol precedes a positive value, false if succeeds.

Returns:

  • (Boolean)

    true if #currency_symbol precedes a positive value, false if succeeds.



166
167
168
# File 'lib/ffi-locale.rb', line 166

def p_cs_precedes
  @p_cs_precedes
end

#p_sep_by_spaceBoolean (readonly)

Returns true iff a space separates #currency_symbol from a positive value.

Returns:

  • (Boolean)

    true iff a space separates #currency_symbol from a positive value.



169
170
171
# File 'lib/ffi-locale.rb', line 169

def p_sep_by_space
  @p_sep_by_space
end

#p_sign_posnInteger (readonly)

0

Parentheses surround the quantity and #currency_symbol.

1

The sign string precedes the quantity and #currency_symbol.

2

The sign string follows the quantity and #currency_symbol.

3

The sign string immediately precedes the #currency_symbol.

4

The sign string immediately follows the #currency_symbol.

Returns:

  • (Integer)

    Positive sign position.



185
186
187
# File 'lib/ffi-locale.rb', line 185

def p_sign_posn
  @p_sign_posn
end

#positive_signString (readonly)

Returns Sign for positive values.

Returns:

  • (String)

    Sign for positive values.



154
155
156
# File 'lib/ffi-locale.rb', line 154

def positive_sign
  @positive_sign
end

#thousands_sepString (readonly)

Returns Thousands separator.

Returns:

  • (String)

    Thousands separator.



123
124
125
# File 'lib/ffi-locale.rb', line 123

def thousands_sep
  @thousands_sep
end