Class: CBETA

Inherits:
Object
  • Object
show all
Defined in:
lib/cbeta.rb

Defined Under Namespace

Classes: BMToText, Gaiji, HTMLToText, P5aToHTML, P5aToText

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCBETA

載入藏經資料



25
26
27
28
29
30
31
32
33
34
# File 'lib/cbeta.rb', line 25

def initialize()
  fn = File.join(File.dirname(__FILE__), 'canons.csv')
  text = File.read(fn)
  @canon_abbr = {}
  CSV.parse(text, :headers => true) do |row|
    next if row['abbreviation'].nil?
  	next if row['abbreviation'].empty?
    @canon_abbr[row['id']] = row['abbreviation']
  end
end

Class Method Details

.linehead_to_s(linehead) ⇒ String

將行首資訊轉為引用格式

Examples:

CBETA.linehead_to_s('T85n2838_p1291a03')
# return "T85, no. 2838, p. 1291, a03"

Parameters:

  • linehead (String)

    行首資訊, 例如:T85n2838_p1291a03

Returns:

  • (String)

    引用格式的出處資訊,例如:T85, no. 2838, p. 1291, a03



17
18
19
20
21
22
# File 'lib/cbeta.rb', line 17

def self.linehead_to_s(linehead)
  linehead.match(/^([A-Z]\d+)n(.*)_p(\d+)([a-z]\d+)$/) {
    return "#{$1}, no. #{$2}, p. #{$3}, #{$4}"
  }
  nil
end

Instance Method Details

#get_canon_abbr(id) ⇒ String

取得藏經略符

Examples:

cbeta = CBETA.new
cbeta.get_canon_abbr('T') # return "【大】"

Parameters:

  • id (String)

    藏經 ID, 例如大正藏的 ID 是 “T”

Returns:

  • (String)

    藏經略符,例如 “【大】”



44
45
46
47
# File 'lib/cbeta.rb', line 44

def get_canon_abbr(id)
	return nil unless @canon_abbr.key? id
	@canon_abbr[id]
end