How to use a condition in Squib with If or Case? #354
-
The following code always returns 'No sun' even if the SunUp variable contains 1 or 2. I noticed that this is because data['SunUp'] is always an array. How can I change certain elements on the cards if a certain condition is met? Using ranges (https://squib.readthedocs.io/en/v0.18.0/arrays.html) seems a lot less flexible.
In the example (https://squib.readthedocs.io/en/v0.18.0/arrays.html#examples), this code is used to identify the Thief and Grifter: Is there any possibility of using case or if when using Squib? If not this would seem like a very useful function. EDIT: For now I solved the problem by generating new image files for each combination of Sun and other powers my cards can have. This is very inefficient because I have to create images for each combination of 3 elements with 5 varieties. Then I dynamically generate the file name in my spreadsheet. So, still looking for a more elegant solution, even if this did work. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
You want to apply the conditional on each element of the array, so it needs to be inside of an iterator. I tend to use png file: data['SunUp'].map {|s| ... } There's an example of doing a different number of images given a number on that array page, starting at line 52. I've seen some folks use the suns = data['SunUp'].map { |s| s.to_i * ":sun:" }
text str: suns, key: ':sun:' do |embed|
embed.png ...
end |
Beta Was this translation helpful? Give feedback.
-
There's always a way! Ruby's Ruby also has the Either of those options along with the new You can do if-statements inside of map. So things like
Uglier option is the ternary operator... so like |
Beta Was this translation helpful? Give feedback.
There's always a way!
Ruby's
nil
has theto_s
method and it returns''
, so I would do"images/#{t.to_s.downcase}1.png"
Ruby also has the
&.
operator as well. Sot&.downcase
would returnnil
ift
was nil. https://ruby-doc.org/core-2.6/doc/syntax/calling_methods_rdoc.htmlEither of those options along with the new
placeholder
option to png would be good.You can do if-statements inside of map. So things like
Uglier option is the ternary operator... so like
data.effect1.map { |e| e.something ? foo : bar }