README.md in highline-2.1.0 vs README.md in highline-3.0.0.pre.1
- old
+ new
@@ -41,15 +41,51 @@
# Default answer
cli.ask("Company? ") { |q| q.default = "none" }
+## Disable default value hint showing
+my_special_default_object = Object.new
+
+cli.ask("Question? ") do |q|
+ q.default = my_special_default_object
+ q.default_hint_show = false
+end
+
+
# Validation
cli.ask("Age? ", Integer) { |q| q.in = 0..105 }
cli.ask("Name? (last, first) ") { |q| q.validate = /\A\w+, ?\w+\Z/ }
+## Validation with custom class
+class ZeroToTwentyFourValidator
+ def self.valid?(answer)
+ (0..24).include? answer.to_i
+ end
+
+ def self.inspect
+ "(0..24) rule"
+ end
+end
+
+cli.ask("What hour of the day is it?: ", Integer) do |q|
+ q.validate = ZeroToTwentyFourValidator
+end
+
+## Validation with Dry::Types
+## `Dry::Types` provides a `valid?` method so it can be used effortlessly
+
+require 'dry-type'
+
+module Types
+ include Dry.Types
+end
+
+cli.ask("Type an integer:", Integer) do |q|
+ q.validate = Types::Coercible::Integer
+end
# Type conversion for answers:
cli.ask("Birthday? ", Date)
cli.ask("Interests? (comma sep list) ", lambda { |str| str.split(/,\s*/) })