Data
チェックやテストに使うデータをdataディレクトリに置く
Gictionary.jsonとかSFCHelp.jsonとか
これらはScrapboxからエクスポートする
/Gictionary, /SFCHelp
面白いデータが欲しいところ
w3mでうまく取得できるページはないか?
code:Makefile
all: gictionary.js SFCHelp.txt
gictionary.js: gictionary.txt
ruby txt2js.rb Gictionary.txt > gictionary.js
gictionary.txt: Gictionary.json
ruby gictionary.rb > gictionary.txt
SFCHelp.txt: SFCHelp.json
ruby json.rb SFCHelp.json > SFCHelp.txt
clean:
/bin/rm -f *~
/bin/rm -f gictionary.js gictionary.txt SFCHelp.txt
code:gictionary.rb
require 'json'
data = File.read("Gictionary.json")
json = JSON.parse(data)
json"pages".each { |page|
word = page"title"
word.gsub!(/\*/,'')
puts word
}
code:txt2js.rb
#
# テキストを、インポート可能なJSファイルにする
#
puts <<EOF
(function () {
let str = ''
EOF
ARGF.each { |line|
line.chomp!
# if line =~ /^\A(?:\p{Hiragana}|\p{Katakana}|ー-|一-龠々)+\z$/ && line.length < 8
if line !~ /'/ && line.length < 8
puts " str += '#{line}\\n'"
end
}
puts <<EOF
exports.data = str
}).call(this)
EOF
ScrapboxのJSONから本文テキストだけ抜き出す
code:json.rb
require 'json'
file = ARGV0
unless file
puts "specify a file"
exit
end
unless File.exist?(file)
puts 'File not found'
end
data = File.read(ARGV0)
json = JSON.parse(data)
json"pages".each { |page|
lines = page"lines"
lines.each { |line|
line.gsub!(/\http.*\/,'')
puts line
}
}