Sha256: e12c0781095c45ffee751aa565a3be1a26043543b3f3ac4b2d90aa1098277d82
Contents?: true
Size: 978 Bytes
Versions: 1
Compression:
Stored size: 978 Bytes
Contents
#!/usr/bin/ruby # # Experiment to work out the implementation of sprintf-like formatting. # # Conclusion: re-opening the module doesn't work well, but I've added it to # en.rb, and it seems to work quite well for most cases. Still having trouble # with 'CONJUNCT'. # # Time-stamp: <31-Oct-2005 06:11:43 ged> # BEGIN { base = File::dirname( File::dirname(File::expand_path(__FILE__)) ) $LOAD_PATH.unshift "#{base}/lib" require "#{base}/utils.rb" include UtilityFunctions } require 'linguistics' Linguistics::use( :en, :classes => [String,Array] ) module Linguistics::EN module_function def lprintf( fmt, *args ) fmt.to_s.gsub( /%([A-Z_]+)/ ) do |match| op = $1 case op when 'PL' args.shift.en.plural when 'A', 'AN' args.shift.en.a when 'NO' args.shift.en.no when 'CONJUNCT' args.shift.en.conjunction else raise "no such formatter %p" % op end end end end try( '"How many %PL do you want?".en.lprintf("monkey")' )
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
eviltrout-linguistics-1.0.6.1 | experiments/lprintf.rb |