Class: Binocs::TUI::SpiritAnimal
- Defined in:
- lib/binocs/tui/spirit_animal.rb
Constant Summary collapse
- ANIMALS =
[ { name: "Fox", trait: "Clever & Quick", art: <<~ART /\\ /\\ //\\\\_//\\\\ ____ \\_ _/ / / / * * \\ /^^^] \\_\\O/_/ [ ] / \\_ [ / \\ \\_ / / [ [ / \\/ _/ _[ [ \\ /_/ ART }, { name: "Owl", trait: "Wise & Watchful", art: <<~ART ,_, (O,O) ( ) -"-"- ^ ^ ART }, { name: "Cat", trait: "Independent & Curious", art: <<~ART /\\_/\\ ( o.o ) > ^ < /| |\\ (_| |_) ART }, { name: "Bear", trait: "Strong & Patient", art: <<~ART ʕ•ᴥ•ʔ /| |\\ _| |_ | | | | |_| |_| ART }, { name: "Rabbit", trait: "Fast & Alert", art: <<~ART (\\(\\ ( -.-) o_(")(") ART }, { name: "Wolf", trait: "Loyal & Fierce", art: <<~ART /\\ /\\ / \\ / \\ / /\\ \\/ /\\ \\ \\/ \\ / \\/ \\ \\/ / \\ ** / \\ -- / \\ / \\/ ART }, { name: "Dragon", trait: "Powerful & Legendary", art: <<~ART ____ / __ \\ /\\_/\\ | | | | ( o.o ) | |__| | > ^ < \\____/ /| |\\ __/ \\__ / | | \\/ \\ / \\ \\__/\\__/ ART }, { name: "Turtle", trait: "Steady & Resilient", art: <<~ART _____ / \\ | O O | \\ ^ / ___/-----\\___ / _______ \\ /___/ \\___\\ ART }, { name: "Phoenix", trait: "Reborn & Radiant", art: <<~ART ,// /// /// /// /\\ /// //\\\\ /// ///\\\\\\ /// /// \\\\\\\\ ///________\\ \\\\\\ \\\\\\\\\\\\\\\\\\\\\\\\ // \\\\\\\\\\\\\\\\\\\\\\\\// \\\\\\ \\\\\\// \\\\\\ \\// \\\\\\ // \\\\\\_// ART }, { name: "Penguin", trait: "Social & Adaptable", art: <<~ART .--. |o_o | |:_/ | // \\ \\ (| | ) /'\\_ _/`\\ \\___)=(___/ ART }, { name: "Octopus", trait: "Creative & Flexible", art: <<~ART ___ .-' '-. / o o \\ | ^ | \\ '---' / /\\/\\/\\/\\/\\/\\/\\ | | | | | | | | ART }, { name: "Unicorn", trait: "Magical & Unique", art: <<~ART \\ \\ \\\\ \\\\ >\\/ /\\ \\ / \\ \\/ \\ `\\ \\ ART } ].freeze
Instance Attribute Summary collapse
-
#animal ⇒ Object
Returns the value of attribute animal.
-
#request ⇒ Object
Returns the value of attribute request.
Attributes inherited from Window
#height, #left, #top, #width, #win
Instance Method Summary collapse
- #draw ⇒ Object
-
#initialize(height:, width:, top:, left:) ⇒ SpiritAnimal
constructor
A new instance of SpiritAnimal.
- #set_request(request) ⇒ Object
Methods inherited from Window
#clear, #close, #copy_to_clipboard, #draw_box, #noutrefresh, #refresh, #resize, #write, #write_centered
Constructor Details
#initialize(height:, width:, top:, left:) ⇒ SpiritAnimal
Returns a new instance of SpiritAnimal.
171 172 173 174 175 |
# File 'lib/binocs/tui/spirit_animal.rb', line 171 def initialize(height:, width:, top:, left:) super @request = nil @animal = nil end |
Instance Attribute Details
#animal ⇒ Object
Returns the value of attribute animal.
169 170 171 |
# File 'lib/binocs/tui/spirit_animal.rb', line 169 def animal @animal end |
#request ⇒ Object
Returns the value of attribute request.
169 170 171 |
# File 'lib/binocs/tui/spirit_animal.rb', line 169 def request @request end |
Instance Method Details
#draw ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/binocs/tui/spirit_animal.rb', line 182 def draw return unless @animal clear draw_box("✨ Spirit Animal ✨") y = 2 # Animal name and trait name_text = "The #{@animal[:name]}" write(y, (@width - name_text.length) / 2, name_text, Colors::HEADER, Curses::A_BOLD) y += 1 trait_text = "\"#{@animal[:trait]}\"" write(y, (@width - trait_text.length) / 2, trait_text, Colors::STATUS_SUCCESS) y += 2 # Draw ASCII art centered art_lines = @animal[:art].lines.map(&:chomp) max_art_width = art_lines.map(&:length).max || 0 art_lines.each do |line| x = [(@width - max_art_width) / 2, 2].max write(y, x, line, Colors::NORMAL) y += 1 end y += 1 # Request info that determined the animal write(y, 2, "Request:", Colors::MUTED, Curses::A_DIM) y += 1 method_str = @request.respond_to?(:read_attribute) ? @request.read_attribute(:method) : @request.method info = "#{method_str} #{@request.path[0, 30]}" write(y, 2, info, Colors::MUTED, Curses::A_DIM) # Footer write(@height - 2, 2, "Press any key to close", Colors::KEY_HINT, Curses::A_DIM) refresh end |
#set_request(request) ⇒ Object
177 178 179 180 |
# File 'lib/binocs/tui/spirit_animal.rb', line 177 def set_request(request) @request = request @animal = pick_spirit_animal(request) end |