Class: String

Inherits:
Object
  • Object
show all
Includes:
When::EncodingConversion
Defined in:
lib/when_exe/core/extension.rb,
lib/when_exe/core/compatibility.rb

Overview

Ruby 1.8.x 系のためのための互換性確保用コード

Instance Method Summary collapse

Methods included from When::EncodingConversion

#+@, #-@, #to_external_encoding, #to_internal_encoding

Instance Method Details

#^(other) ⇒ When::TM::TemporalPosition の “^”演算結果

Note:

core/extension

self をWhen.exe Standard Expression とみなして When::TM::TemporalPosition を生成し“^”演算を実行

Returns:



401
402
403
# File 'lib/when_exe/core/extension.rb', line 401

def ^(other)
  When::TM::TemporalPosition._instance(self, {}) ^ other
end

#calendarWhen::TM::Calendar Also known as: to_calendar

Note:

core/extension

self をプレフィクス ‘_c:’ を省略した IRI とみなして When::TM::Calendar を取得

Returns:



260
261
262
# File 'lib/when_exe/core/extension.rb', line 260

def calendar
  When::Parts::Resource._instance(self, '_c:')
end

#calendar_eraWhen::TM::CalendarEra Also known as: to_calendar_era

Note:

core/extension

self をプレフィクス ‘_e:’ を省略した IRI とみなして When::TM::CalendarEra を取得



296
297
298
# File 'lib/when_exe/core/extension.rb', line 296

def calendar_era
  When::Parts::Resource._instance(self, '_e:')
end

#calendar_noteWhen::TM::CalendarNote Also known as: to_calendar_note

Note:

core/extension

self をプレフィクス ‘_c:’ を省略した IRI とみなして When::TM::CalendarNote を取得

Returns:

  • (When::TM::CalendarNote)


284
285
286
# File 'lib/when_exe/core/extension.rb', line 284

def calendar_note
  When::Parts::Resource._instance(self, '_n:')
end

#clockWhen::Parts::Timezone::Base Also known as: to_clock

Note:

core/extension

self を時間帯文字列とみなして When::Parts::Timezone::Base を取得



272
273
274
# File 'lib/when_exe/core/extension.rb', line 272

def clock
  When.Clock(self)
end

#encode(code) ⇒ String

encode

Parameters:

  • code (String)

    文字コード

Returns:

  • (String)

    文字コードcode に変換した文字列



22
23
24
# File 'lib/when_exe/core/compatibility.rb', line 22

def encode(code)
  return Iconv.iconv(code, 'UTF-8', self)[0]
end

#calendar_era(options = {}) ⇒ Array<When::TM::CalendarEra> Also known as: to_era

Note:

core/extension

self を検索する暦年代とみなして登録された When::TM::CalendarEraを検索

see alse When.era

Parameters:

  • options (Hash) (defaults to: {})

Returns:

  • (Array<When::TM::CalendarEra>)

    検索結果を When::TM::CalendarEra オブジェクトの Array で返す。 ヒット数が不足している場合は、setup で指定した順序で When::TM::CalendarEra オブジェクトを 生成しつつ読み込んで検索する。



338
339
340
# File 'lib/when_exe/core/extension.rb', line 338

def era(*args)
  When::TM::CalendarEra._instance(*([self] + args))
end

#ideographic_unification(pattern = When::Locale._unification) ⇒ String

包摂リストに登録されている文字を包摂する

Parameters:

  • pattern (Hash) (defaults to: When::Locale._unification)

    包摂ルール

Returns:



235
236
237
# File 'lib/when_exe/core/extension.rb', line 235

def ideographic_unification(pattern=When::Locale._unification)
  When::Locale.ideographic_unification(self, pattern)
end

#m17nWhen::BasicTypes::M17n

Note:

core/extension

self をプレフィクス ‘_m:’ を省略した IRI とみなして When::BasicTypes::M17n を取得



308
309
310
# File 'lib/when_exe/core/extension.rb', line 308

def m17n
  When::Parts::Resource._instance(self, '_m:')
end

#ordInteger

文字列の先頭文字のコードを取得する (多バイト文字非対応)

Returns:

  • (Integer)


53
54
55
# File 'lib/when_exe/core/compatibility.rb', line 53

def ord
  self[0]
end

#resource(namespace = nil) ⇒ When::Parts::Resource Also known as: to_resource

Note:

core/extension

self を IRI とみなして When::Parts::Resource を取得

Parameters:

  • namespace (String) (defaults to: nil)

    デフォルトの namespace

Returns:



248
249
250
# File 'lib/when_exe/core/extension.rb', line 248

def resource(namespace=nil)
  When::Parts::Resource._instance(self, namespace)
end

#to_m17nWhen::BasicTypes::M17n

Note:

core/extension

self を When::BasicTypes::M17n に変換する



211
212
213
# File 'lib/when_exe/core/extension.rb', line 211

def to_m17n
  When::BasicTypes::M17n.new(self)
end

#to_month_nameWhen::BasicTypes::M17n Also known as: month_name

Note:

core/extension

月名

self の最初の3文字から決定した月名を返します。 一致する月名がない場合、名前の一致するその他のM17nを探して返します。 (self が M17n なら name 自身をそのまま返します)

Returns:



389
390
391
# File 'lib/when_exe/core/extension.rb', line 389

def to_month_name
  When::BasicTypes::M17n.month_name(self)
end

#to_pairWhen::Coordinates::Pair Also known as: pair

self を幹と枝の要素と解釈してWhen::Coordinates::Pair を生成



318
319
320
# File 'lib/when_exe/core/extension.rb', line 318

def to_pair
  Coordinates::Pair._force_pair(self)
end

#to_rNumeric

to_r(もどき)

文字列を Rational or Integer に変換する

Returns:



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/when_exe/core/compatibility.rb', line 34

def to_r
  case self
  when /\.|E/i
    to_f.to_r
  when /\//
    Rational
    Rational(*split(/\//).map {|v| v.to_i})
  else
    to_i
  end
end

#to_residueWhen::Coordinates::Residue Also known as: residue, day_of_week

Note:

core/extension

曜日(剰余類)

self の最初の3文字から決定した七曜(剰余類)を返します。 一致する七曜(剰余類)がない場合、名前の一致するその他の剰余類を探して返します。

Returns:



372
373
374
# File 'lib/when_exe/core/extension.rb', line 372

def to_residue
  When::Coordinates::Residue.to_residue(self)
end

#translate(loc = '') ⇒ String Also known as: /

Note:

core/extension

特定 locale に対応した文字列の取得

Parameters:

  • loc (String) (defaults to: '')

    locale の指定

Returns:

  • (String)

    loc に対応した文字列



223
224
225
226
# File 'lib/when_exe/core/extension.rb', line 223

def translate(loc='')
  return encode($1) if loc =~ /\.(.+)\z/
  return self
end

#when?(options = {}) ⇒ When::TM::TemporalPosition Also known as: tm_pos, to_tm_pos

Note:

core/extension

self をWhen.exe Standard Expression とみなして When::TM::TemporalPosition を生成

Parameters:

  • options (Hash) (defaults to: {})

    暦法や時法などの指定

Returns:

See Also:



354
355
356
# File 'lib/when_exe/core/extension.rb', line 354

def when?(options={})
  When.when?(self, options)
end