Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify ranges in YAML?

Tags:

syntax

yaml

I can express

3rd page is the title page

in YAML

title: 3

What about the following?

Pages 10 to 15 contains chapter 1

One way is

chapter 1: [10, 11, 12, 13, 14, 15]

I would prefer a range here. Is there anything like that in YAML?

chapter 1: (10..15)

** Update **

The following would be my alternative if there is no such thing as range in YAML

chapter 1:
   start page: 10
   end page: 15
like image 963
rpattabi Avatar asked Jul 26 '10 16:07

rpattabi


2 Answers

There is not direct way to specify ranges in YAML, but some YAML can store serialized objects, for example in Ruby:

...
normal range: !ruby/range 10..20 
exclusive range: !ruby/range 11...20 
negative range: !ruby/range -1..-5 
...

Look here

like image 175
Mikhail Chernykh Avatar answered Oct 05 '22 17:10

Mikhail Chernykh


Range is application specific. The following may be meaningful for some applications:

-1 .. Q

a .. Щ

23 .. -23.45

1 .. 12:01:14 (both are integers in YAML !)

But the ruby way is also unclear since it does not say whether the end values are included or not: 10 .. 15

(Are you only talking about ranges of integers ?)

like image 31
Andrey Avatar answered Oct 05 '22 18:10

Andrey