Module: SearchPi
- Includes:
- BigMath
- Defined in:
- lib/search_pi.rb,
lib/search_pi/version.rb
Constant Summary collapse
- VERSION =
"1.0.0"
Instance Method Summary collapse
Instance Method Details
#find(number, pattern) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/search_pi.rb', line 11 def find(number, pattern) source = number.to_s regex = Regexp.new pattern.to_s match_pos = source.index regex return nil if match_pos.nil? pre_match = source[( (match_pos - 10) >= 0 ? (match_pos - 10) : 0 )..(match_pos-1)] post_match = source[(match_pos + pattern.to_s.size + 1)..(match_pos + pattern.to_s.size + 11)] {pre_match: pre_match, match_pos: match_pos, post_match: post_match, match: pattern} end |
#pi(precision) ⇒ Object
7 8 9 |
# File 'lib/search_pi.rb', line 7 def pi(precision) BigDecimal(PI(precision)) end |