Class: RubyMotionQuery::Format

Inherits:
Object
  • Object
show all
Defined in:
motion/ruby_motion_query/format.rb

Class Method Summary (collapse)

Class Method Details

+ (Object) date(date, format)

rmq.format.date(Time.now, 'EEE, MMM d, "yy')

See <www.unicode.org/reports/tr35/tr35-19.html#Date_Format_Patterns> for more information about date format strings.



27
28
29
# File 'motion/ruby_motion_query/format.rb', line 27

def date(date, format)
  RubyMotionQuery::Format.date_formatter(format).stringFromDate(date)
end

+ (Object) date_formatter(format)



42
43
44
45
46
47
48
49
50
51
52
53
# File 'motion/ruby_motion_query/format.rb', line 42

def date_formatter(format)
  @_date_formatters ||= {}

  # Caching here is very important for performance
  @_date_formatters[format] ||= begin
    format_template = NSDateFormatter.dateFormatFromTemplate(format, options:0,
                                                      locale: NSLocale.currentLocale)
    date_formatter = NSDateFormatter.alloc.init
    date_formatter.setDateFormat(format_template)
    date_formatter
  end
end

+ (Object) numeric(number, format) Also known as: number

rmq.format.number(1232, '#,##0.##')



18
19
20
# File 'motion/ruby_motion_query/format.rb', line 18

def numeric(number, format)
  RubyMotionQuery::Format.numeric_formatter(format).stringFromNumber(number)
end

+ (Object) numeric_formatter(format)



31
32
33
34
35
36
37
38
39
40
# File 'motion/ruby_motion_query/format.rb', line 31

def numeric_formatter(format)
  @_numeric_formatter ||= {}

  # Caching here is very important for performance
  @_numeric_formatter[format] ||= begin
    number_formater = NSNumberFormatter.alloc.init
    number_formater.setPositiveFormat(format)
    number_formater 
  end
end